PHP mail from address header - php

I'm using PHP mail function to send messages from my web app.
I've created a table which holds the e-mail addresses and messages to send. The script fetches a certain number of messages and sends them.
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=' . $charset . "\r\n";
$headers .= 'To: ' . $destName . ' <' . $destAddress . '>' . "\r\n";
$headers .= 'From:' . $fromName . ' <' . $fromAddress . '>' . "\r\n";
$headers .= "Reply-To: ". $fromName . ' <' . $fromAddress . '>' . "\r\n";
mail($destAddress, $subject, $msgBody, $headers);
My problem is that, even setting the FROM and REPLY-TO header, the address shown on the list of received messages is strange (not the one I've sent). See picture below,
But when I open the message, it seems all is OK, ie the sender is the one I've configured.
Can anyone help me?

If there would be nothing that shows that the "from" and "reply-to" field are different from the address from where the mail was sent, then everyone would be able to sent you a mail coming from for instance obama#whitehouse.org
If you want the email of your choice to be shown, you should use smtp, log in to the mailserver with the correct account, and sent the mail. This will cause the mail to be verified and trusted.
http://www.9lessons.info/2009/10/send-mail-using-smtp-and-php.html

This is probably an issue with the web interface of dispostable.com which does not show the contents of the "from" but the address of the sending mailserver in the overview. This might be a security measure. Dis you try to send to a "normal" address?
By the way, the address in "from" should be resolvable to the server from where it was sent. For example a mail from admin#abcdefg.com should come from the server ip of abcdefg.com. Else it will be calssified as spam by some mail clients or mail servers.

Related

PHP Sending Mail with Headers to Gmail

The mail() function in PHP works fine when sending to Gmail if I don't specify any headers. However, as soon as I try to add in headers, the function still returns true but I never get the email. The Gmail server seems to reject the delivery.
These are the headers I'm using:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: ' . $username . ' <' . $email . '>' . "\r\n";
$headers .= 'From: Blahblah <email#example.com>' . "\r\n";
mail($email, 'Subject', '<html><body>Body of message</body></html>', $headers);
I was hoping that someone could point out to me the flaw? I grabbed most of this code straight from the PHP manual, so one could understand my confusion and frustration. Thanks!
The bigger email services will not deliver mail sent from your own personal server in this manner.
Due to SPAM issues. All the big mail providers require SPF records, DKIM, and reverse DNS before they will accept your mail.
Some live/hotmail user's are not receiving html mail
Personally I prefer to be rid of that hassle and use a 3rd party mail server for all of my outgoing mails to my users.
$Headers .= "From: $Yourname <$YourEmail>\r\n";
or
$Headers .= 'From: '.$Yourname.'<'.$Youremail.'>'."\r\n";
or
$Headers .= 'From: '.$Yourname.' <".$Youremail.">' . "\r\n";
Give a try if any of this work?

Small amount of users receiving HTML email as source code

I've already asked this question before : HTML Email occasionally sending source code
But it seems that these solutions did not fix the problem.
We send HTML emails to our customers using PHP containing an order confirmation. The vast majority of customers receive these emails fine.
However some users (people who have a private domain name) receive these emails as the source code. After making some tweaks to the headers, the problem now only occurs for a minority of users, and not for all users with a private domain name.
One of our customers sent us this, which is what he received as well as the email source code:
MIME-Version: 1.0
Content-type: text/html; charset=iso-8859-1
X-MessageSniffer-Identifier: e:\SmarterMail\Spool\proc\work\1136252898525.eml
X-GBUdb-Analysis: 1, 162.13.103.84, Ugly c=0 p=0 Source New
X-MessageSniffer-Scan-Result: 0
X-MessageSniffer-Rules: 0-0-0-16102-c
X-RBL-Warning: BADROUTE: This E-mail was routed in a poor manner consistent with spam [2000010f].
X-RBL-Warning: ENVMISMATCH: Env sender (apache#513421-db1.comms-express.com) From: (websales#comms-express.com) mismatch.
X-Declude-Sender: apache#513421-db1.comms-express.com [162.13.103.84]
X-Declude-Spoolname: 1136252898525.eml
X-Declude-RefID:
X-MessageStream-Note: Scanned by MessageStream (www.messagestream.com).
X-MessageStream-Scan: Score [4] at 13:23:17 on 01 May 2014
X-MessageStream-Tests: BADROUTE, ENVMISMATCH
X-Country-Chain: 'EU' [corrupt RIPE data]->UNITED KINGDOM->destination
I have never seen something like this so I don't even know where to begin. Hopefully someone can point me in the right direction?
These are my headers:
$from = $from . ' ';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=utf-8" . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$headers .= 'Reply-To: ' . $from . "\r\n";
$headers .= 'Return-Path: ' . $from . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion() . "\r\n";
$headers .= 'X-Originating-IP: ' . $_SERVER['SERVER_ADDR'] . "\r\n";
It sounds to me like those users have their e-mails turned into txt types of files, not HTML files to be interpreted. The stuff you posted in the header is a normal e-mail header that is hidden from users who read the message, then stripped by the part that produces the message for the user. I was once asked by a supervisor to authenticate the message, and that's essentially what it said.

PHP mail script goes to junk mail when using an auto generated URL

Here is the PHP code I am using to send my email. For some reason this will go to junk mail if I include the following line: $message .= WEBSITE_URL . '/violation.php?email=' . urlencode($fm_email) . "&key=$activation"; but if I remove this it will come to my inbox.
Can anyone help me solve this issue to allow this url in my email?
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: My Name <noreply#myname.com>' . "\r\n";
$subject = 'Subject is here';
$message = "Here is the message";
$message .= WEBSITE_URL . '/violation.php?email=' . urlencode($fm_email) . "&key=$activation";
mail($fm_email, $subject, $message, $headers);
Dont use mail() function of php it will send your mail to junk only. Instead use SMTP php mailer function.
Why we should use SMTP instead PHP mail():
SMTP log in to an actual account on a mailserver and send the mail through SMTP to another mail server. If the mail server is configured correctly, your mails are sent from an actual account on a mailserver and will not wind up flagged as spam.
Mail sent with the mail() function is sent with sendmail in most cases. There is no authentication going on and it will almost always be flagged as spam if you use the "From:" in the extra headers.
This is because if you take a look at an original email file in say, gmail, you will see the headers that are sent. You are actually sending from user#serverhostname.tld and not someone#example.com like you had told the mail function to do.
If you use SMTP and view the original the email is actually sent from someone#example.com
You can download SMTP class from:
https://code.google.com/a/apache-extras.org/p/phpmailer/source/browse/trunk/class.smtp.php?r=170
http://www.phpclasses.org/package/14-PHP-Sends-e-mail-messages-via-SMTP-protocol.html
Using the following headers should prevent your email from getting in the junk/spam folder.
$headers = 'From: ' . $website_name . ' <' . $own_emailaddress . '>' . PHP_EOL;
$headers .= 'Reply-To: ' . $name_sender . ' <' . $email_sender . '>' . PHP_EOL;
$headers .= 'Return-Path: Mail-Error <' . $error_emailaddress . '>' . PHP_EOL;
$headers .= 'X-Mailer: PHP/' . phpversion() . PHP_EOL;
$headers .= 'X-Priority: Normal' . PHP_EOL;
$headers .= 'MIME-Version: 1.0' . PHP_EOL;
$headers .= 'Content-type: text/html; charset=iso-8859-1' . PHP_EOL;
Don't forget to define the variables in the code.

To send email in Bcc to multiple users no "TO" user

I am tring to sent email to multiplw users in Bcc through PHP mail scriptcode is as follows -
$recipients =array('recpient1#gmail.com','recpient2go#gmail.com');
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$to = '';
$subject = "E-mail subject";
$body = "E-mail body";
$headers = 'From: info#mydomain.com' . "\r\n" ;
$headers .= 'Reply-To: info#mydomain.com' . "\r\n";
$headers .= 'BCC: ' . implode(', ', $recipients) . "\r\n";
$email =mail($to, $subject, $body, $headers);
if we leave $to black then user in gmail detail shows "to undisclosed recipients" and Bcc not shows how can be show "Bcc me (user who got mail)" i search a lot, but didn't got any proper answer
BCC stands for Blind Carbon Copy and its main purpose is, that you can not see the other recipients of that mail.
If you want to show all email addresses use CC (Carbon Copy) instead.
Be aware, though, that all recipients now can see all other recipients' email addresses, which increases the probabilities having those email addresses end up in spam catalogs.
You can't control how the people at Gmail decide to display the recipients list when reading an email. Each webmail system decides how they want to display the recipients list.
Maybe you can fin another webmail system that decided to display "Sent to me#my-email" instead of "Undisclosed recipients"...but why does it matter to you?
Why do you care about that? I'd say it is a false problem. Since you received the email, it was of course sent to you.

PHP mail() -f parameter is NOT working

I've researched this intensely. Here, at Stack Overflow, I've figured out that one needs to use an -f parameter with the php mail() function, if one wants undeliverable mail to bounce back. Following is my script (as it stands now):
//Send Confirmation email. Following are the variables for the email
// mail function best practices: http://collaborate.extension.org/wiki/Best_Practices_Using_the_PHP_mail_Function
$sendto = $email; // this is the email address collected from the foreach routine.
$e_subject = stripslashes($subject); // Subject
//$message = "<html>" . stripslashes($body) . "</html>";
$message = "
<html>
<body>
<p>Hello " . stripslashes($fName) . ":</p>
<div>" . stripslashes($body) . "</div>
</body>
</html>
";
// Always set content-type when sending HTML email
$header = "MIME-Version: 1.0" . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";;
// extract user domain so you can set up X-Mailer
$u_domain=substr(strrchr($user_email, '#'), 1);
$dom_array = explode(".",$u_domain);
$user_domain = $dom_array[0];
$header .= "X-Mailer: ". $user_domain ."\r\n";
$header .= "X-Sender-IP: {$_SERVER['REMOTE_ADDR']}\r\n";
$header .= "X-Originating-IP: [".getenv("REMOTE_ADDR")."]\r\n";
$header .= "From: " . $user_email . "\r\n";
$header .= "Sender: ". $user_email . "\r\n";
// The "envelope sender" is the address listed in the "Return-Path:" header - and controls where the email is sent to in the event that a recipient address bounces. http://collaborate.extension.org/wiki/Best_Practices_Using_the_PHP_mail_Function
$header .= "Return-Path:" . $user_email . "\r\n";
$header .= "Reply-To:" . $user_email . "\r\n";
$bounceTo = "-f". $user_email;
// Collect variables from above and insert into the mail() function.
mail($sendto, $e_subject, $message, $header,$bounceTo);
You'll notice a lot of commenting - I'm just trying to figure this out. My mail() sends wonderfully. The mail is coming into my inbox with formatting as it should be. But... the $bounceTo variable ("-f" . $user_email) is not working. I've intentionally mailed to 3 known inactive addresses, and I'm not getting any bounce backs.
All the header settings in the above code are in place because I've learned that these may affect bounce backs. I'm totally willing to get rid of un-necessary headers and add what is necessary. But... at this point the script seems to be a mess -which is not producing bounce backs.
Any suggestions are welcome.
Thanks Much:
Pavilion
Have you looked at the comment posted at http://www.php.net/manual/en/function.mail.php#107321. That might lead you in the right direction.
This thread explaining bounced mail in php might be of benefit to you. I personally have never had to use the -f parameter to handle bounced emails.
Overriding the bounce address with -f is not allowed on all servers, especially if you are on a shared hosting server this is often not possible. In this case, it's often better not to use the very limited mail() function but use a smtp library like phpmailer or swiftmailer instead.
Btw: you don't have to send mails to an inactive address to check your bounce address. Send them to an active account, in the message source look for the "Return-Path" header, this is the bounce address.

Categories