Home > Tutorials > PHP > Sending Emails
Sending Emails
Automated emails are great for sending messages to and from the users of your website and yourself. They are also good for sending emails whenever an error occurs on your website. To send an email, use the following code:
$sendTo="info@webdevelopersforums.com";
$subject="Sending email with PHP";
$message="Isn't this easy?! All you need to send emails with PHP is a few lines of code!";
$headers="From: Somewhere@someone.com";
mail($sendTo,$subject,$message,$headers);
$sendTo specifies the where the email is going.
$subject specifies the subject of the email.
$message is the body text of the email. New lines in the email need to be specied using '\n', and should be kept to 70 characters or fewer.
$headers are any additional headers for the email, using the form <Header Name>: <value>, and are separated using '\r\n'. Unless it is set in php.ini, a 'From' header MUST be included.
For more information on sending emails, see the PHP manual at www.PHP.net.
Comment on this page:
Comments
No one has commented on this lesson yet. You can be the first!