About Linux FAQ

Browse More FAQs:

Change the From: email address in PHP mail()

Posted by Vivek Gite [Last updated: January 3, 2007]

Q. How do I change the email address in PHP mail() function?

A. The php mail() function allows you to send email.

mail() syntax:
bool mail ( string to, string subject, string message [, string additional_headers [, string additional_parameters]] )

Where,
=> to: Receiver, or receivers of the mail.

=> subject: Subject of the email to be sent.

=> message: Message to be sent.

=> additional_headers: String to be inserted at the end of the email header.
This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (\r\n).

string additional_headers is use to specify From: email address in PHP. Generally you write mail() as follows:

<?
$message = "This is a test";
mail('user@domain.com', 'Subject', $message);
?>

If you would like to add From : email address

Use code as follows:

<?php
$to      = 'user@domain.com';
$subject = 'Subject';
$message = 'This is a test';
$headers = 'From: webmaster@yourdot.com' . "\r\n" .
   'Reply-To: webmaster@yourdot.com' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

References

E-mail this to a friend      Printable version

Related Other Helpful FAQs:

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.