Page 1 of 1

help in the mail () function!

Posted: Mon Apr 28, 2008 3:28 am
by tabariz
Does anybody know how can I change the name of the sender when using the mail function,
everytime I use this code the name of the sender is the name of the external server and using and other bunch of characters!

Code: Select all

<?php
$to = "recipient@example.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
  echo("<p>Message successfully sent!</p>");
 } else {
  echo("<p>Message delivery failed...</p>");
 }
?>

Re: help in the mail () function!

Posted: Mon Apr 28, 2008 4:29 am
by andym01480
The PHP manual is pretty cool

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);
?>
So...

Code: Select all

<?php
$to = "recipient@example.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$headers = 'From: webmaster@example.com' . "\r\n" .
   'Reply-To: webmaster@example.com' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();
if (mail($to, $subject, $body,$headers)) {
  echo("<p>Message successfully sent!</p>");
 } else {
  echo("<p>Message delivery failed...</p>");
 }
?>