Forum Moderators: coopster
I found a few posts about this problem, and saw a suggestion which I tried, but it still does not set the "From:" value when my script sends email. My code is hosted on an Apache server. The "Reply-To:" gets set successfully, but not the "From:". I added the Mime-Version line and the Content-type line from the suggestion I saw on this site. But that made no difference.
Here's what I am using (I've left out the code where I set the $emailAddr, $subject and $message, but they come thru in the email just fine). Can anyone help?
$headers =
"MIME-Version: 1.0\r\n" .
"Content-type: text/plain; charset=utf-8\r\n" .
"From: \"$senderName\" <$senderEmailAddr>" . "\r\n" .
"Reply-To: \"$senderName\" <$senderEmailAddr>" . "\r\n" .
"X-Mailer: PHP/" . phpversion() . "\r\n";
mail($emailAddr, $subject, $message, $headers );
Thx,
Rich
I think you have too many quotation marks. Try testing with this code.
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: $name <$email>' . "\r\n";
$headers .= 'From: $name <$email>' . "\r\n";
mail($email, $subject, $message, $headers);
Note that the $name is not enclosed in quotation marks. Hope this helps.
persepee, I tried your code, and it failed because of the single quotes. The single quotes treated the $senderName and $senderAddr variables as literals and thus their values were not substituted in. I changed the single quotes to double quotes and your code worked the same as my code (except the Content-type: text/html messed of the formatting of the email message text, but I understand that).
Hence, I am still not getting the From: value in the email header to change to the senders addr.
However, the code (my original code) is successful at setting the Reply-To: value in the email header. Therefore, even though the email displays (in my yahoo inbox) as though it was sent from my web host's server, when I hit the "Reply" button and I'm taken to the "Compose a reply email" page, the To: field is populated with the Reply-To: value that I set in the header. So, that is good news, and evidence that I am successfully setting some values in the header.
This is good, but I want the person who eventually receives these email messages to see the From: field properly populated so that they know (before hitting Reply, or before even reading the email) to see the From: value that I have set (or am trying to set).
FYI, it looks like my server is running PHP 4.3.10.
I'm new to PHP. And I've seen briefly a reference to an ini file. Is it possible that I'm missing some setup file on my website that is required to make this From: feature work. I doubt this is the problem, since the Reply-To: feature does in fact work,,, but I'm grasping at straws. Or is it possible the problem is with some recipient email servers. Could it be a Yahoo problem (I ask that because I'm testing using my yahoo email account, and it's not working)? Again, I'm just shooting at ideas in the dark.
This PHP email seems like such a simple task, I'm guessing I'm missing something fundamental and so obvious, that I'm just looking right over it.
Thanks,
Rich
The only thing I can think is that maybe there's a problem with your mail server changing the headers. You might want to try using telnet to access your SMTP port and try it by hand.
Here's the way I tried it on my server. (with my domain edited out). The starred lines are what I typed, but you don't want to type the stars, obviously. If doing this still doesn't send the From header, you can be sure the mail server is removing it.
*[root@server root]# telnet ********.com 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 server.********.com ESMTP
*HELO localhost
250 server.********.com
*MAIL FROM: <fromEmailAddress@********.com>
250 ok
*RCPT TO: <******@yahoo.com>
250 ok
*DATA
354 go ahead
*From: "My name here" <******@********.com>
*Subject: Subject goes here.
*message body here.
*.
250 ok 312791916 qp 52101
*QUIT
221 ********.com
Connection closed by foreign host.
[root@server root]#
Sorry about all the raw SMTP, but that's really the only way to be sure of what's being sent. You can run telnet from Windows or Unix at the command line.