1. Home
  2. Computing & Technology
  3. Email

How to Send Emails with Extra Headers in PHP

By Heinz Tschabitscher, About.com

Sending emails with PHP is easy. All you need is a function and three arguments.

Add another argument and you can specify extra headers like "X-Mailer", "Cc:" or "From:" (sic), for example. If you specify more than one extra header, make sure you separate them with "\r\n" to make sure they work as intended.

Send Emails with Extra Headers in PHP — Example

An example of a simple message with extra headers could look like this:

<?php
$to = "recipient@example.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$headers = "From: sender@example.com\r\n" .
    "X-Mailer: php";
if (mail($to, $subject, $body, $headers)) {
  echo("<p>Message sent!</p>");
 } else {
  echo("<p>Message delivery failed...</p>");
 }
?>
More Email Quick Tips

Explore Email

More from About.com

  1. Home
  2. Computing & Technology
  3. Email
  4. How Email Works
  5. Email Programming Tips
  6. How to Send Emails with Extra Headers in PHP - About Email

©2008 About.com, a part of The New York Times Company.

All rights reserved.