Jump to content

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 = '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!!!!

Link to comment
https://forums.phpfreaks.com/topic/101950-solved-mail-headers-missing/
Share on other sites

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)

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

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

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

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

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.