Page 1 of 1

mail() function sender details

Posted: Sun Aug 27, 2006 6:04 am
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

Re: mail() function sender details

Posted: Sun Aug 27, 2006 6:06 am
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";

Posted: Sun Aug 27, 2006 8:20 am
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.

Posted: Sun Aug 27, 2006 8:28 am
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