raindropz Posted April 20, 2008 Share Posted April 20, 2008 Hi. I'm using the mail() function to send external mails. So, I set the the subject, body and aditional headers of the email and send it. But when I check the mail that has been sent, one of the header fields is missing (The filed "Sender"). <?php $to = '[email protected]'; $subject = 'Mail test Subject'; $body = 'Mail test Body'; $headers = 'From: [email protected]'; $headers .= 'Sender: [email protected]'; mail ($to, $subject, $body, $headers); ?> The "Sender" header isn't sent. I'm in a shared hosting, so I was thinking that it could be filtering it, but when I ask them, they told me that not. So maybe the problem is mine. I have algo tried the mail() -f parameter, but the Sender field is still missing when i send the mail. mail ($to, $subject, $body, $headers, '[email protected]'); Well, I hope somebody could help me! Any ideas?? Thanks!!!! Link to comment https://forums.phpfreaks.com/topic/101950-solved-mail-headers-missing/ Share on other sites More sharing options...
jonsjava Posted April 20, 2008 Share Posted April 20, 2008 from PHP.net: <?php $to = '[email protected]'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); ?> I.E. you forgot to add "\ n" (without the space) Link to comment https://forums.phpfreaks.com/topic/101950-solved-mail-headers-missing/#findComment-521737 Share on other sites More sharing options...
raindropz Posted April 20, 2008 Author Share Posted April 20, 2008 Thanks for the quick reply jons, I forgot the CLRF in my post! But the problem is still happening. [email protected] *must* be in the "From" field. and [email protected] *must* be in the "Sender" field. I need to do it in this way, due to the nature of the email (they are contacts invitations, and I don't want my emails get to the "junk mail" folder). Reply-to, and X-Mailer could be used too, but they are not a problem. -Thanks Link to comment https://forums.phpfreaks.com/topic/101950-solved-mail-headers-missing/#findComment-521740 Share on other sites More sharing options...
jonsjava Posted April 20, 2008 Share Posted April 20, 2008 unfortunately, you will always hit the junk folder, because you are sending as a non-authoritative address (you are not authorized to send email as the domain that you are sending as). The only way to fix this is create an e-mail account like [email protected] and have your subject say "a message was sent to you by <user email address>". Link to comment https://forums.phpfreaks.com/topic/101950-solved-mail-headers-missing/#findComment-521741 Share on other sites More sharing options...
jonsjava Posted April 20, 2008 Share Posted April 20, 2008 to get a better understanding, go to this topic Link to comment https://forums.phpfreaks.com/topic/101950-solved-mail-headers-missing/#findComment-521742 Share on other sites More sharing options...
raindropz Posted April 20, 2008 Author Share Posted April 20, 2008 That's right. But even if I'm sending it as a non-authoritative address, the "Sender" field should be present if I set it. Am I right? Link to comment https://forums.phpfreaks.com/topic/101950-solved-mail-headers-missing/#findComment-521747 Share on other sites More sharing options...
jonsjava Posted April 20, 2008 Share Posted April 20, 2008 to be honest, I use the mime-mail class at phpguru.com . Here's a good simple mailer script for you: <?php $to = "[email protected]"; $subject = "My email test."; $message = "Hello, how are you?"; $headers = "From: [email protected]\r\n"; $headers .= "Reply-To: [email protected]\r\n"; $headers .= "Return-Path: [email protected]\r\n"; $headers .= "CC: [email protected]\r\n"; $headers .= "BCC: [email protected]\r\n"; if ( mail($to,$subject,$message,$headers) ) { echo "The email has been sent!"; } else { echo "The email has failed!"; } ?> Link to comment https://forums.phpfreaks.com/topic/101950-solved-mail-headers-missing/#findComment-521748 Share on other sites More sharing options...
jonsjava Posted April 20, 2008 Share Posted April 20, 2008 oops, here's a modified one for your needs: <?php $to = '[email protected]'; $subject = 'Mail test Subject'; $body = 'Mail test Body'; $headers = 'From: [email protected]\r\n'; $headers .= 'Reply-To: [email protected]\r\n'; $headers .= 'Return-Path: [email protected]\r\n'; mail ($to, $subject, $body, $headers); ?> Link to comment https://forums.phpfreaks.com/topic/101950-solved-mail-headers-missing/#findComment-521749 Share on other sites More sharing options...
jonsjava Posted April 20, 2008 Share Posted April 20, 2008 or you wanting sender's name? <?php $sender = $_POST['name']; $sender_email = $_POST['mail_from']; $to = '$_POST['mail_to']'; $subject = 'Check out this site!'; $site_name = "http://site.com"; $replyto = "[email protected]"; $body = $_POST['message']."\n"; $body .= "---------------------\nCome take a look at {$site_name}!"; $headers = "From: \"{$sender}\"<{$mail_from}>\r\n"; $headers .= "Reply-To: {$replyto}\r\n"; $headers .= "Return-Path: {$replyto}\r\n"; mail ($to, $subject, $body, $headers); ?> Link to comment https://forums.phpfreaks.com/topic/101950-solved-mail-headers-missing/#findComment-521750 Share on other sites More sharing options...
raindropz Posted April 20, 2008 Author Share Posted April 20, 2008 Thanks for the script jons, but the Sender field is still missing. According to the RFC 2822: The originator fields indicate the mailbox(es) of the source of the message. The "From:" field specifies the author(s) of the message, that is, the mailbox(es) of the person(s) or system(s) responsible for the writing of the message. The "Sender:" field specifies the mailbox of the agent responsible for the actual transmission of the message. For example, if a secretary were to send a message for another person, the mailbox of the secretary would appear in the "Sender:" field and the mailbox of the actual author would appear in the "From:" field. If the originator of the message can be indicated by a single mailbox and the author and transmitter are identical, the "Sender:" field SHOULD NOT be used. Otherwise, both fields SHOULD appear. Link to comment https://forums.phpfreaks.com/topic/101950-solved-mail-headers-missing/#findComment-521753 Share on other sites More sharing options...
raindropz Posted April 20, 2008 Author Share Posted April 20, 2008 Damn... 2 days, and 13 f*ng hours of researching, but I finally hit the answer. The problem was that my hosting support was lying.... they DO ARE filtering that header... but, it seems that they don't even know it... They uses EXIM as the ESMPT server. I have been reading the exim manual, and I get with this: 49.11 The Sender header For locally-originated messages, unless originated by a trusted user, any existing Sender: header is removed. For non-trusted callers, unless local_from_check is set false, a check is made to see if the address given in the From: header is the correct (local) sender of the message (prefixes and suffixes for the local part can be permitted via local_from_prefix and local_from_suffix). If not, a Sender: header giving the true sender address is added to the message. No processing of the Sender: header is done for messages originating externally. So this is it. I can sleep now . Link to comment https://forums.phpfreaks.com/topic/101950-solved-mail-headers-missing/#findComment-521772 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.