Change FROM in email message

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
PHP-bie
Forum Newbie
Posts: 1
Joined: Sat Feb 04, 2006 12:36 pm
Location: raleigh

Change FROM in email message

Post 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]
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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
highonsnow
Forum Newbie
Posts: 5
Joined: Sat Feb 04, 2006 1:59 pm

Post 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());
?>
Post Reply