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 = 'to_user@toexample.com'; $subject = 'Mail test Subject'; $body = 'Mail test Body'; $headers = 'From: from_user@example.com'; $headers .= 'Sender: invite@my-web.com'; 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, '-finvite@my-web.com'); Well, I hope somebody could help me! Any ideas?? Thanks!!!! Quote 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 = '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); ?> I.E. you forgot to add "\ n" (without the space) Quote 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. from_user@example.com *must* be in the "From" field. and invite@my-web.com *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 Quote 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 checkthisout@yourdomain.com and have your subject say "a message was sent to you by <user email address>". Quote 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 Quote 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? Quote 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 = "yourplace@somewhere.com"; $subject = "My email test."; $message = "Hello, how are you?"; $headers = "From: myplace@here.com\r\n"; $headers .= "Reply-To: myplace2@here.com\r\n"; $headers .= "Return-Path: myplace@here.com\r\n"; $headers .= "CC: sombodyelse@noplace.com\r\n"; $headers .= "BCC: hidden@special.com\r\n"; if ( mail($to,$subject,$message,$headers) ) { echo "The email has been sent!"; } else { echo "The email has failed!"; } ?> Quote 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 = 'to_user@toexample.com'; $subject = 'Mail test Subject'; $body = 'Mail test Body'; $headers = 'From: from_user@example.com\r\n'; $headers .= 'Reply-To: invite@my-web.com\r\n'; $headers .= 'Return-Path: invite@my-web.com\r\n'; mail ($to, $subject, $body, $headers); ?> Quote 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 = "info@yoursite.com"; $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); ?> Quote 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. Quote 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 . Quote Link to comment https://forums.phpfreaks.com/topic/101950-solved-mail-headers-missing/#findComment-521772 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.