Written by Dany Matta

Continued from page 1


Dany S. Matta is the webmaster of The Winner List & Reserve Your Future Sites . This website includes over 10,000 free articles to improve your internet profits, enjoyment and knowledge. Web Site Address: & Free Safelist: Daily Tips:

Autoresponders With PHP

Written by Robert Plank

Continued from page 1

body of my message."); ?>

Replace "" with your actual e-mail address, but be *sure* to keep quotes around it. Save it, and upload mailtest.php to your web server and run it inrepparttar 105088 browser. You should see a blank page. Wait a few minutes and check your mail. You should see a mysterious mail message in your box withrepparttar 105089 subject "Hello" andrepparttar 105090 message "Hi. This isrepparttar 105091 body of my message."

If you're using a free e-mail service or a weird ISP,repparttar 105092 message won't come through because a lot of mail servers these days require that certain headers are present inrepparttar 105093 message.

Let's do that now.

What's below isn't important enough to explain thoroughly, but it's just header information that is interpreted byrepparttar 105094 mail server. This data tells us that we're sending a plain text e-mail, thatrepparttar 105095 message came from your e-mail address (and gives your name), and tells us thatrepparttar 105096 e-mail "client" we used was PHP.

$headers = "Content-Type: text/plain; charset=us-ascii From: $myname <$mymail> Reply-To: <$mymail> Return-Path: <$mymail> X-Mailer: PHP";

This isrepparttar 105097 code you should have by this point, complete withrepparttar 105098 header information andrepparttar 105099 variables which tellrepparttar 105100 script what your name and e-mail address are:

$email = "";

$myname = "Your Name Here"; $mymail = "";

$headers = "Content-Type: text/plain; charset=us-ascii From: $myname <$mymail> Reply-To: <$mymail> Return-Path: <$mymail> X-Mailer: PHP";

mail($email,"Hello","Hi. This isrepparttar 105101 body of my message.",$headers);


Notice how we've simplified things a bit by using variables inrepparttar 105102 mail() function. That way we don't have to retype things. This method also looks better (in my opinion anyway) and is easier to tweak once you're ready to actually customize it for yourself.

Try this out again. Believe it or not, but you just made your first autoresponder! Before we move on let's make this look even cleaner:

$myname = "Your Name Here"; $mymail = "";

$subject = "Hello"; $body = "Hi. This isrepparttar 105103 body of my message. Notice how I can continue typing right onrepparttar 105104 next line!";

$headers = "Content-Type: text/plain; charset=us-ascii From: $myname <$mymail> Reply-To: <$mymail> Return-Path: <$mymail> X-Mailer: PHP";

if ($email != "") { mail($email,$subject,$body,$headers); }


All I did here was just make things look nicer, but notice how I removedrepparttar 105105 line that set $email to "" This is becauserepparttar 105106 value of $email will be passed torepparttar 105107 script from that form we made earlier.

This also sendsrepparttar 105108 e-mail message ONLY ifrepparttar 105109 value of $email is not blank. So if someone just hitrepparttar 105110 submit button without entering an address,repparttar 105111 script won't try to sendrepparttar 105112 e-mail message.

Everything should be ready for you to try out now. Re-upload "some-script.php" and go to signup.html. Enter your e-mail address inrepparttar 105113 field, hit submit and wait for that mail message to arrive.

There's only one step left to making this autoresponder complete. And that's sendingrepparttar 105114 user somewhere so they aren't given a blank page.

Find this line in your script: if ($email != "") { mail($email,$subject,$body,$headers); }

And paste this directly underneath it: header("Location:"); die();

Tryrepparttar 105115 autoresponder out. You'll see that oncerepparttar 105116 autoresponse message is sent, you're directed to Now, go ahead and change it to whatever URL you want to use. Or, make use it with a variable sorepparttar 105117 end result is like this:

$myredirect = " hankyou.html";

$myname = "Your Name Here"; $mymail = "";

$subject = "Hello"; $body = "Hi. This isrepparttar 105118 body of my message. Notice how I can continue typing right onrepparttar 105119 next line!";

$headers = "Content-Type: text/plain; charset=us-ascii From: $myname <$mymail> Reply-To: <$mymail> Return-Path: <$mymail> X-Mailer: PHP";

if ($email != "") { mail($email,$subject,$body,$headers); } header("Location:$myredirect"); die();


Don't forget to changerepparttar 105120 values above. " hankyou.html" needs to point torepparttar 105121 URL where thankyou.html is stored.

You're done. Don't forget to send John feedback for me. If you're really curious as to how to do something in PHP, I might just write an article on it.

Article by Robert Plank PHP Newsletter:


    <Back to Page 1 © 2005
Terms of Use