Jump to content

Build Theme!
  •  
  • Infected?

WE'RE SURE THAT YOU'LL LOVE US!

Hey there! :wub: Looks like you're enjoying the discussion, but you're not signed up for an account. When you create an account, we remember exactly what you've read, so you always come right back where you left off. You also get notifications, here and via email, whenever new posts are made. You can like posts to share the love. :D Join 91674 other members! Anybody can ask, anybody can answer. Consistently helpful members may be invited to become staff. Here's how it works. Virus cleanup? Start here -> Malware Removal Forum.

Try What the Tech -- It's free!


Photo

Using the mail(); Function in PHP for Auto-reply


  • Please log in to reply
2 replies to this topic

#1 GaryORLFC

GaryORLFC

    Authentic Member

  • Authentic Member
  • PipPip
  • 56 posts
  • Interests:Sports, Music, Gaming, Computers & Drinks With Friends.

Posted 09 May 2012 - 04:27 PM

Hi there,

I'm having trouble with trying to get an auto-reply working suing the mail(); function.

So far I have this:

<?php

if (isset($_POST['contact_name']) && isset($_POST['contact_email']) && isset($_POST['contact_text']))
{
$contact_name = $_POST['contact_name'];
$contact_email = $_POST['contact_email'];
$contact_subject = $_POST['contact_subject'];
$contact_text = $_POST['contact_text'];

if(!empty($contact_name) && !empty($contact_email) && !empty($contact_subject) && !empty($contact_text)){

$to = 'me@live.ie';
$subject = $contact_subject;
$body = 'From: '.$contact_name."\n\n".$contact_text;
$headers = 'From: '.$contact_email;

$subject1 = 'Thank you for contacting...';
$autoreply = "Thank you for contacting...";
$headers1 = "From: me@me.ie";

if (mail($to, $subject, $body, $headers)){
if (mail($contact_email, $thanks{

}
echo 'Thank you. Your e-mail has been sent.';
}
else{
echo 'Sorry, an error occurred, please try again later';
}

} else{
echo 'All fields must be filled in';
}
}

?>


Now, I do realise that the following have not yet been put into a mail(); function
$subject1 = 'Thank you for contacting...';
$autoreply = "Thank you for contacting...";
$headers1 = "From: me@me.ie";

But where do I make the second mail function?

Basically, it's for a contact form, and when the user submits the contact form, the admin will get the details of that form submitted, but then I want the user to also receive an e-mail from me saying that we have received their contact form and that we will be with them shortly.

Anyone know how to do this?

EDIT: Sorry, I put this in the wrong section of the forums, I'm quite tired :smack:

Edited by GaryORLFC, 09 May 2012 - 04:28 PM.

Posted Image

    Advertisements

Register to Remove


#2 Ztruker

Ztruker

    WTT Tech

  • Tech Team
  • 7,778 posts
  • Interests:Helping people fix MS Windows related computer problems of all kinds.

    Good, inexpensive wine (not an oxymoron).

Posted 10 May 2012 - 06:59 PM

I find when writing any code, it helps me a lot to structure it so I can see what belongs where. Many programmers don't need to do this but I do, so what you have I would make look like this:
<?php
if (isset($_POST['contact_name']) && isset($_POST['contact_email']) && isset($_POST['contact_text']))
  {
	$contact_name = $_POST['contact_name'];
	$contact_email = $_POST['contact_email'];
	$contact_subject = $_POST['contact_subject'];
	$contact_text = $_POST['contact_text'];

	if(!empty($contact_name) && !empty($contact_email) && !empty($contact_subject) && !empty($contact_text))
	  {
		$to = 'me@live.ie';
		$subject = $contact_subject;
		$body = 'From: '.$contact_name."\n\n".$contact_text;
		$headers = 'From: '.$contact_email;

		$subject1 = 'Thank you for contacting...';
		$autoreply = "Thank you for contacting...";
		$headers1 = "From: me@me.ie";

		if (mail($to, $subject, $body, $headers))
		  {
			if (mail($contact_email, $thanks))   // <<< You had a few missing ))s here
			{
			  echo 'Thank you. Your e-mail has been sent.';  // and this was outside the closing brace.
			  //
			  // Your 2nd mail would go here I believe
			  //
			}
		  }
		else
		  {
			echo 'Sorry, an error occurred, please try again later';
		  }
		}
	  else
		{
		  echo 'All fields must be filled in';
		}
  }
?>
But maybe I'm not following what you want.

Rich

Artificial intelligence is no match for natural stupidity.


#3 appleoddity

appleoddity

    SuperMember

  • Tech Team
  • 3,071 posts
  • Interests:Eating, Movies, Family, Church, Music, Volleyball, Softball, Poker, Computers, Electronics, Reading.

Posted 04 June 2012 - 09:16 PM

Gary I see some syntax errors in this code. What exactly is the problem you are having?

Let me point out a couple of tips that you should follow.

First, placing this on a website for feedback without a captcha will generate about 99 spam e-mails for about every 1 good one. Spam bots fill these things out automatically. Use a captcha to force the user to type in a code to send the text.

Second, you should never allow a form like this to send an e-mail reply back to the user. Think about it. You just made your website a hacker gateway. All a troublemaker has to do is fill out the form with spam, put in someone else's e-mail address, and then submit the form. They just made your website send somebody else an e-mail. That's not good. The only confirmation the user needs is on the website itself. When they submit the form, they either get a positive response or a negative response. Period. No e-mails back to them. Only an outgoing e-mail to the hostmaster or webmaster, or whoever.

Check out my website contact form: http://crystalpc.us/contact.php - Test it out. I don't care. If you like what you see, I'll send you the code I used and you can modify it how you want. To use captcha you have to setup an account at recaptcha.org and they have all the instructions and examples how to use the captcha form in your website. They generate a unique security key for you to use.

Take care

The help you have been given is free. If you have been happy with our help please consider donating to support this forum.

If you would like to say thanks for the help I have given you please View My Profile and Leave a Comment.
Your encouragement is welcome.

Related Topics



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users