Jump to content

[SOLVED] mail() headers missing


raindropz

Recommended Posts

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

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)

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

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>".

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!";
   }
?>

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);
?>

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);
?>

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.

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 :).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.