Page 1 of 1

Change FROM in email message

Posted: Sat Feb 04, 2006 12:42 pm
by PHP-bie
hawleyjr | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


I am trying to send a message that does not look like it is from the root of the server but from our client.  Yes, safe mode is OFF.  This script would send an email message and originate from service@mysite.com (instead of appearing as it does now from the root at the server).  I receive the Warning: mail(): SAFE MODE Restriction in effect. The fifth parameter is disabled in SAFE MODE. in /usr/local/4admin/apache/vhosts/mysite.com/httpdocs/sendmail.php on line 17 message when I try:

Code: Select all

<?php
   $to = "me@home.com";
   $title = "Support subscription confirmation";
			$mailheaders = "From: My Site <service@mysite.com>"; $mailheaders = "Reply - To: service@mysite.com";

$body = <<< emailbody
Dear subscriber,

This email confirms your purchase of a 30 day
email support subscription. Please direct all 
requests to service@mysite.com.

Thank you,
My Site

emailbody;
   $success = mail($to,$from,$title,$body, $mailheaders);
?>
Can you tell me what I'm doing wrong?


hawleyjr | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Sat Feb 04, 2006 2:02 pm
by josh
Can you put a phpinfo(); script up and link it or paste it's output?

Also if you just want a quick fix you should be able to set the default from header in php.ini

Posted: Sat Feb 04, 2006 2:06 pm
by highonsnow
Hi there.. You have overwritten $mailheaders with your "Reply - To"..

I believe you should try this instead:

Code: Select all

$mailheaders = "From: My Site <service@mysite.com>";
$mailheaders .= "Reply - To: service@mysite.com"; // Pay particular attention to the " .= "
or else you could refer to the example provided in the PHP Manual (modified to make it easier to look at):

Code: Select all

<?php
mail("recipient@domain.com", "the subject", $message,
     "From: From Name <webmaster@domain.com>\r\n" .
     "Reply-To: Reply to  <webmaster@domain.com>\r\n" .
     "X-Mailer: PHP/" . phpversion());
?>