Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cwesty

macrumors member
Original poster
Oct 22, 2005
50
0
Hello everyone.

I'd like to be able to send email confirmation to users who submit a form on my site in php.
Does anyone know how this is done?

* I just simply want a very basic email message to be sent to a user, but can't seem to find what I'm looking for.

Any help would be appreciated.
 
The mail function in PHP is pretty simple.

mail($recipient, $subject, $message, $sender);

You can define those variables earlier in the script or write the information in the function itself (i.e. mail(you@email.com, this is the subject, This is the message, me@email.com);)
You can place it inside an if statement so that the email gets sent if the script is successful.

Hope this makes sense, I'm writing this in a hurry.
 
Something like this is what you are after.

Code:
   $message = "Thank you for submitting a form";
   $email = $_POST["useremail"]
   $subject = "Form confirmation";
   $header = "From: email@yoursite.com\n"
   
   mail($email,$subject,$message,$header);

You will have to make sure that mail is allowed by your webhost (it should be, but some free hosts disallow it) for this to work.
 
Also, if you want to have a verification system, you can generate a random code (the first few characters of an md5 checksum of a random string works well), store it in the database, send it with the email, and check that code against the one in the database when they go to verify. This is how I do it, anyway.

And, on the side.. does anyone have a link that tells me how to send HTML e-mails with mail()?
 
Coolnat2004 said:
Also, if you want to have a verification system, you can generate a random code (the first few characters of an md5 checksum of a random string works well), store it in the database, send it with the email, and check that code against the one in the database when they go to verify. This is how I do it, anyway.

And, on the side.. does anyone have a link that tells me how to send HTML e-mails with mail()?
HTML is a markup language, not a programming language. You can't send email with just HTML.
 
thejadedmonkey said:
HTML is a markup language, not a programming language. You can't send email with just HTML.
....mail() being the mail() function in PHP, that is used to send email. I am asking how to send an HTML-formatted message with the mail() function in PHP..
 
Coolnat2004 said:
And, on the side.. does anyone have a link that tells me how to send HTML e-mails with mail()?

I think you can add this information to the "header" of your mail, like this:

Code:
$header  = "From: email@yoursite.com (Your Name)\r\n";
$header .= "Content-Type: text/html\r\nContent-Transfer-Encoding: 8bit";

Then HTML markups should work just like you use them in HTML pages.
 
Make sure you do sanity checking, on the $sender variable especially, or some spammer bot is going to 'h4x0r' your script with an injection attack and use it to spam people.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.