469,903 Members | 1,493 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ


Sending E-Mail with PHP

By Blair Ireland
Senior Editor, TheScripts.com

Ok, time to teach you the mail function in PHP.

The basic syntax for the mail function is;

mail(string to, string subject, string message, string
[additional_headers]);

So, to send an email to me, it would look like;

mail("bireland@visuart-design.com", "the subject", "Line
1\nLine 2\nLine 3");

Arguments:

String to: The address of the person the e-mail is going to String Subject: The subject of the e-mail String message: The actual message in the e-mail [additional_headers]: These are extra's you want the e-mail to have, such as the following;

"From: webmaster@$SERVER_NAME Reply-To:
webmaster@$SERVER_NAME

and more.

Each extra header must be separated by a \n , or a newline. So, to send an email to me, it would look like;

mail("bireland@visuart-design.com", "the subject", "Line
1\nLine 2\nLine 3", "From: you@yoursite.com\nReply-To:
me@mysite.com\n);

That's It!!

So lets implement this into the tellus.php3 script. We will send two total e-mails, one to the person who used the form, and one to the webmaster of the site.

<?

PRINT "<center><FONT SIZE=-1 face=verdana>"; PRINT "Greetings $name, thank you for filling out our";
PRINT "form.";
PRINT "</center><p><center><TABLE border=0 width=500";
PRINT "cellspacing=0 cellpadding=7>"; PRINT "<TR><TD><FONT SIZE=-1 face=verdana>"; PRINT "In the form, you stated that our site";
PRINT "$status. Thank you for your input."; PRINT "We will send you more information about our site";
PRINT "in an email to $email.";
PRINT "If you have any more comments, feel free to reply.";
PRINT "</FONT></TD></TR></TABLE></center>";

mail("$email", "Site Information", "Hello $name,\nWe thank
you again for using our form and telling \nus your option
about our site\n\nThis is important to us so we can know how
to improve.\n\nThank you once again.");

mail("webmaster@thescripts.com", "An Opinion", "$name just
used the form.\n\nThey stated that our site $opinion.");

?>

Remember to save this as tellus.php3 and try it out on your site.

« PHP Forms Script