I am sending emails using php's mail function. Some addresses in email clients such as aol, hotmail.com and msn are not receiving it. Gmail works fine! I find it strange as it can pass through Gmail but not others:
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers = "From: $from";
$headers .= "\r\nMIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
And then I am sending email using:
$ok = #mail($to, $subject, $message, $headers);
For diagnostic purposes $header string contains:
From: xxx#example.com
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="==Multipart_Boundary_xd31b2fcd6941ba77b38f866330c24944x"
and the $message string contains:
This is a multi-part message in MIME format.
--==Multipart_Boundary_x0dde39863d56158409aa962fc1dd9a3bx
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
The email message appears here
--==Multipart_Boundary_x0dde39863d56158409aa962fc1dd9a3bx
Content-Type: {"application/octet-stream"};
name="afile.pdf"
Content-Disposition: attachment;
filename="afile.pdf"
Content-Transfer-Encoding: base64
The attachment's contents here
--==Multipart_Boundary_x0dde39863d56158409aa962fc1dd9a3bx
Some addresses in email clients such as aol, hotmail.com and msn are not receiving it
Your code is not the best place to start investigating this - check your email logs and bounce messages in the first place. The most likely cause is that your email is being flagged as a spam. You could verify this by setting up a mailbox yourself and sending mesages to it. How to prevent your emails being flagged as spam is a question which has been asked and answered here many times.
I am not sure whether the header is correct
It would have been mkore helpful to see an example of the email and headers generated (trimed down to a sensible size).
Related
I'm trying to send e-mails which an e-mail client will collect together under the same thread.
I am trying to do this using the In-Reply-To header, or the References header.
This is how I add them:
$this->withSwiftMessage(function ($message) use ($header, $messageId) {
$headers = $message->getHeaders();
$headers->addTextHeader('X-SMTPAPI', $header);
$headers->addTextHeader('References', $messageId);
$headers->addTextHeader('In-Reply-To', $messageId);
});
The headers are showing in my mail:
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
References: 8def8ad2ba46673db3886aaef3bb230f#swift.generated
In-Reply-To: 8def8ad2ba46673db3886aaef3bb230f#swift.generated
but the messages are in separate threads (in Gmail).
Any ideas?
Mick
My goal is to anwer to a mail to a email that is in a inbox of a mailbox.
I am at the point that I can read the mail out of the mailbox and I can send emails.
The only thing is that I would like it for the receiver of the email that all the conversations are wrapped in 1 email. You know with gmail you see for example a subject like this:
(5) Test subject
This means that this mails contains 5 submails.
But at this point everytime I send a answer to the existing email with php it comes in as a completely new mail. And it does not stack on top of eachother.
Does anyone know how to make these emails stack on eachother.
My current code for sending the mail:
// 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";
$headers .= "Reply-To: reply#reply.nl \r\n";
// Additional headers
$headers .= "From: sender#sender.nl\r\n";
mail("test#test.nl", "test subject", "test message", $headers);
You have to include the In-Reply-To and the References Header.
In In-Reply-To is the Message-ID-Header you are directly refering too and References are commaseperated values of all messages (e.g. when you reply back and forth, then it would make sense to include all of the message IDs)
Example:
In-Reply-To: <GDKDHK#web.de>
References: <a1gjkr#googlemail.com>,<GDKDHK#web.de>
You need to RE: subject so that they can stack in the email viewer.
I write a script to send email from my website. I recieve email in inbox in gmail, outlook and hotmail but in yahoo, its going to SPAM folder and also URL in not working in yahoo. Whats wrong in my code,
Header
$headers = "MIME-Version: 1.0 \r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \r\n";
$headers .= "From: $Name <$Email> \r\n";
$headers .= "Reply-To: $Email\r\n";
Message with URL
$message.= "<a href='https://www.google.com'>Click here</a>";
PHP-Mail function is not uses a well configured SMTP Server so may be this is a reason or try to Use the PHPMailer-Class. or you need to try with full headers
Also links not working cause your mail in spam. need to move in inbox and see.
http://www.velvetblues.com/web-development-blog/avoid-spam-filters-with-php-mail-emails/
For more info follow:- sending email via php mail function goes to spam
I've searched and searched for a solution to this but to no avail.
I'm using the php mailer to send out a mixed text / html email, encoded in utf8. Here's the relevant code:
$headers = "From: $fromPerson\r\n" .
"Content-Transfer-Encoding: 8bit\r\n".
"Reply-To: $fromPerson\r\n" .
"Content-Type: multipart/alternative; boundary=". $mime_boundary_header. "\r\n" .
"X-Mailer: PHP/" . phpversion();
$message = "$notice_text
--$mime_boundary
Content-Type: text/plain; charset='UTF-8'
Content-Transfer-Encoding: 8bit
$textEmail
--$mime_boundary
Content-Type: text/html; charset='UTF-8'
Content-Transfer-Encoding: 8bit
$htmlEmail
--$mime_boundary--";
//mb_detect_encoding($message) returns UTF-8
$mail_sent = #mail( $to, $subject, $message, $headers);
The messages contain Spanish along with those tricky characters. The emails display fine in gmail, hotmail (online outlook), mac mail, phones etc. but not in Windows live mail or Microsoft outlook.
If I manually set the default font in Windows live Mail to utf8 the message displays correctly, but otherwise it does not. If I forward the email from another client to outlook or windows live it displays fine as well.
I could find work arounds I'm sure, but am I missing something? I don't want to rely on the receivers knowing how to change the encoding of the message, so is there something I need to add to the email to prompt these clients to recognise the encoding?
I apologise if this has been dealt with elsewhere, and I'll appreciate any advice. It looks like I should just go ahead and use PHPMailer to see if that fixes the problem, but out of personal curiosity it would be interesting to learn why this is happening...
I'm not sure that the ' wrapping the charset are necessary, or even correct. Try removing them:
Content-Type: text/plain; charset=UTF-8
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: example#example.com\r\n";
$headers .= "Reply-To: example#example.com\r\n";
A modification to Riko's answer makes for a little cleaner code.
$header_array = [
"MIME-Version: 1.0",
"Content-type: text/html; charset=UTF-8",
"From: example#example.com",
"Reply-To: example#example.com"
];
$headers = implode("\r\n", $header_array);
I'm using a PHP script to email a posting to Tumblr and Posterous. For Posterous special characters are showing up in the posting but for Tumblr it don't.
(In general Tumblr does support special character - I tried it out with emailing from Gmail)
So what could be the problem?
Here my PHP header:
$headers .= "MIME-Version: 1.0\r\n"
."Content-Type: multipart/alternative; boundary=\"PHP-mixed-$bound_text\"\r\n";
$message = "--PHP-mixed-$bound_text\r\n"
."Content-Type: multipart/related; type=\"text/html\"; boundary=PHP-mixed2-$bound_text\r\n\r\n"
."--PHP-mixed2-$bound_text\r\n"
."Content-Type: text/html; charset=\"utf-8\"\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n";
I already tried several charsets and Content-Transfer-Encoding combinations without any different result.
Any ideas are welcome.
Michael
I looked into how my GMail account sent it and found out it used windows-1252 for the charset and the text is base64 encoded (this may not be case in using other GMail accounts). The email I sent below was successfully posted by tumblr and I used the function utf8_decode to generate the correct base64 string.
$data = wordwrap(base64_encode(utf8_decode($stringWithSpecialCharacters)));
The raw email message is below:
To: myuploademail#tumblr.com
Subject: tumblr post from sudocode
from: omime class <script#sudocode.net>
MIME-Version: 1.0
Content-type: multipart/alternative;
boundary=omime_1308940625_c0d4e36fd504619028804e8b23ceb12a
--omime_1308940625_c0d4e36fd504619028804e8b23ceb12a
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: base64
38TW+eLq7vT76//mP9nCys4=
--omime_1308940625_c0d4e36fd504619028804e8b23ceb12a
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: base64
38TW+eLq7vT76//mP9nCys4=
--omime_1308940625_c0d4e36fd504619028804e8b23ceb12a--
I used my omime class to send the email and here's the code I used:
$email = new omime('alternative');
$email->attachText('ßÄÖùâêîôûëÿæœÙÂÊÎ');
$email->attachHTML('ßÄÖùâêîôûëÿæœÙÂÊÎ');
$email->send('mysecretuploademail#tumblr.com', 'test tumblr post', 'from: omime class <script#sudocode.net>');