Web Design, Development & Marketing

Web Development Articles

PHP: Send Mail Function / Script

Here is a useful function for sending an email using PHP. The PHP mail() function uses the local sendmail binary so this needs to be available for the mail() function to work properly.

For more information see PHP Mail Functions.

<?php
// where the message is to be sent
$to = "recipient@address.co.uk";
// message subject
$subject = "Your Email Subject";
// extra header information
$headers = "From: you@address.co.uk";
// mail content
$contents = "Your message here\nAnother line of text here";
if (mail($to, $subject, $contents, $headers))
{
  echo "<p>Message Sent</p>";
}
else
{
  echo "<p>Message Failed</p>";
}
?>

The mail() function in PHP returns true if the mail was successfully accepted for delivery. It is worth noting that this does not guarantee that the mail message reaches the specified recipient.

Subscribe to RSS Feed Bookmark and Share

Related Links

Related Articles / Posts

Barclaycard ePDQ CPI Integrations (27/05/2009)

HSBC XML API / CPI E-commerce Integrations (02/04/2009)

Recommended Open Source Invoicing System (25/03/2009)

Recent Recommended Links - October 2008 (03/10/2008)

Controlling PHP Register Globals Using .htaccess File (04/03/2008)