mail() function sender details

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tommy1987
Forum Commoner
Posts: 92
Joined: Tue Feb 21, 2006 8:35 pm

mail() function sender details

Post by tommy1987 »

I am trying to set up an automatic mailer from a website, everything works apart from I am a little unhapy because the server appears in the from field, can I change this to some text of my choice, or a return email address?

Thanks very much in advance, Tom
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: mail() function sender details

Post by Chris Corbyn »

tommy1987 wrote:I am trying to set up an automatic mailer from a website, everything works apart from I am a little unhapy because the server appears in the from field, can I change this to some text of my choice, or a return email address?

Thanks very much in advance, Tom
Use the additional headers parameter in mail().

Code: Select all

$headers = "From: Your Name <your@address.com>\r\n";
$headers .= "Reply-To: Your Name <your@address.com>\r\n";
tommy1987
Forum Commoner
Posts: 92
Joined: Tue Feb 21, 2006 8:35 pm

Post by tommy1987 »

Please can you give a peice of example code, I am not familiar with using headers.

e.g.

Code: Select all

$headers = "From: Blah Blah <blah@blah.com>\r\n"; 
  $headers = "Reply-To: Tom lansdale <blah@blah.com>\r\n"; 
  mail($to, $subject, $body);
I cant seem to get it to work, excuse my ignorance, I am a newcomer to PHP.
screevo
Forum Commoner
Posts: 25
Joined: Fri Aug 25, 2006 12:04 am

Post by screevo »

tommy1987 wrote:Please can you give a peice of example code, I am not familiar with using headers.

e.g.

Code: Select all

$headers = "From: Blah Blah <blah@blah.com>\r\n"; 
  $headers = "Reply-To: Tom lansdale <blah@blah.com>\r\n"; 
  mail($to, $subject, $body);
I cant seem to get it to work, excuse my ignorance, I am a newcomer to PHP.
http://www.php.net/mail

You'll notice when you put code in the PHP brackets, functions get underlined. You can click on the function and bring up an explanation of its use. Also, http://www.php.net has great resources on all functions, and an easy to use search in the upper right.

From what I linked:

Code: Select all

<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
   'Reply-To: webmaster@example.com' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();

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