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.
Related
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?
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.
So, its coming towards the time of year again when our sports club mailing list gets swamped with new members (happens with the new academic year).
Last year we tried sending emails using php's mail() function.
This worked fine for around the first 50 or so (and continues to work fine sending one email at a time). However, after around 50, mail() claimed it had sent the mail, but no one ever received them on the other end.
I should point out, that in my implementation it simply does a loop through all the emails in our database and runs the following function:
function sendMail($from,$fromname,$to,$subject,$body){
$subject = stripslashes($subject);
$body = nl2br(stripslashes($body));
$headers = '';
$headers .= "From: $fromname <$from>\n";
$headers .= "Reply-to: $fromname <$from>\n";
$headers .= "Return-Path: $fromname <$from>\n";
$headers .= "Message-ID: <" . md5(uniqid(time())) . "#" . $_SERVER['SERVER_NAME'] . ">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "Date: " . date('r', time()) . "\n";
return mail($to,$subject,$body,$headers);
}
Does anyone know what could have caused this?
You are probably being blocked by ratelimit on the SMTP relay.
I would suggest instead of sending individual emails, set everyone to the BCC field, with no one in the TO and CC field.
$headers .= 'Bcc: ' . implode(",", $email_array) . "\r\n";
Using Bcc without "To:"-Header makes the E-Mail "To:"-Header "undisclosed-recipients", those mails usually getting blocked by strict servers. I would not recommend this for newsletter stuff,´ you will get blacklisted.
If you send this mail to a few users at the same ISP, you will get blacklisted for sure.
I would recommend a script which sends an amount of mails every 30 mins or so.
I am using the following code to send email to members of my site. The script works and the email is recieved by the user. But, I do encounter encoding problems when emailing to Hotmail or Notes.
The code:
$to = "to#email.com";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/plain; charset="utf-8"; format="flowed"' . "\r\n";
$headers .= 'Content-Transfer-Encoding: 8bit'. "\n\r\n";
$headers .= "To: John Doe<john#doe.com>" . "\r\n" .
"From: John Smith<john#smith.com" . "\r\n" .
"Reply-To: john#doe.com" . "\r\n" .
"Return-Path: john#doe.com" . "\r\n" .
"Sender: john#doe.com" . "\r\n" .
"X-Sender: john#doe.com" . "\r\n" .
"X-Mailer: JohnDoe". "\r\n".
"X-Report-Abuse: Please report abuse to: john#doe.com";
//If the e-mail was successfully sent...
$subject = $translation[104];
if(mail($to, $subject, $message, $headers)){
}
Both the message and the subject contains the swedish letters Å, Ä and Ö. The actual message is correctly encoded and viewed in Hotmail, while the subject is not. You can view the image below for more information:
Image: http://www.aspkoll.se/imgo/649
I am confused. I've googled for days and tried different kind of solutions, but without any success I am afraid.
Can you please help me with this problem?
Appreciated!
Email subjects, and other header content, such as names, are encoded using RFC 2047
php.net comments on mail() give the following example:
mail($mail, "=?utf-8?B?".base64_encode ($subject)."?=", $message, $headers);
Try http://www.phpclasses.org/browse/file/919.html. It works for Yahoo mail, Gmail, Hotmail.
P.S.: Hotmail sucks. :)
Most email clients have problems reading CSS in HTML emails (including Gmail and Hotmail). I often use this service to convert my HTML/CSS to proper email format so that everything looks normal on the user's end. Basically what it does is convert all CSS to inline styles:
http://premailer.dialect.ca/
Do any of you have any other methods for sending CSS in your HTML emails? I automatically generate the emails, and due to some restrictions, I can't modify the the inline styles.
As for direct format, I've always done inline CSS styling, however I use SwiftMailer (http://swiftmailer.org/) for PHP5 to handle email functionality and it has helped immensely.
You can send multipart messages with different formats so if the email client doesn't like the HTML version, you can always default to the text version so you know at least something is getting through clean.
In your "views" folder, you can set apart routes for different email formats (I use smarty too, hence the .tpl extension). Here's what a typical SwiftMailer::sendTemplate() function would look like when you're setting up the templates:
$email_templates = array('text/html' => 'email/html/' . $template . '.en.html.tpl',
'text/plain' => 'email/text/' . $template . '.en.txt.tpl');
foreach ($email_templates as $type => $file) {
if ($email->template_exists($file)) {
$message->attach(new Swift_Message_Part($email->fetch($file), $type));
} elseif ($type == 'text/plain') {
throw new Exception('Could not send email -- no text version was found');
}
}
You get the idea. SwiftMailer has a bunch of other good stuff, including returning "undeliverable" addresses, logging delivery errors, and throttling large email batches. I'd suggest you check it out.
You need to add a header that says the content is HTML. When you use the mail() function, one of the headers should be: Content Type: html/text (That might not be the 'exact' header).
Let me find you an example: (From the php.net/mail page)
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
To add to the above example, (in case you don't know PHP very well), you just have to build the "email" using the variables: to, subject, message, and headers
Let me know if you want to know how to create a form to fill and run this PHP script, otherwise, you can simply enter everything in this file manually, save as a PHP file, throw it up on a server that supports PHP, and navigate to the file in your browser.
Here's the code:
// Setup recipients
$to = 'johndoe#google.com' . ',' // comma separates multiple addresses
$to .= 'janedoe#msn.com';
// subject
$subject = 'PHP Email Script - Test Email';
// message (to use single quotes in the 'message' variable, supercede them with a back slash like this--> \'
$message = '
<html>
<head>
<title>PHP Email Script</title>
</head>
<body>
<p style="background: #ccc; width: 100%;">Test Email Script</p>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
// Send the email
mail($to, $subject, $message, $headers);
the easiest way is to write a html page with embedded css and push it through automated styling machine