I'm using PHP to send out a multipart/mixed message (plain text, html and attachments). However, whilst it works for most accounts, Yahoo, GMail and Sky seem to show blank emails. Where as everything else seems to display the email. ANY HELP WOULD BE GREATLY APPRECIATED!
My headers are
$headers .= "Content-Type: multipart/mixed; boundary=\"mixed-" . $random_hash . "-mixed\"\n";
$headers .= "MIME-Version: 1.0\n";
And the content is;
--mixed-7df05b31-mixed
Content-Type: multipart/alternative; boundary="alt-7df05b31-alt"
--alt-7df05b31-alt
Content-Type: text/plain; charset=utf-8
Hello how are you? I am just checking the mailing function.
Hopefully this will work!
Cheers.
--alt-7df05b31-alt
Content-Type: text/html; charset=utf-8
<div style="font-family:Arial, Helvetica, sans-serif; font-size: 10pt;">
<div>
Hello how are you? I am just <b>checking</b> the mailing function.<br><br>
Hopefully this will work!<br><br>
Cheers.</div></div>
--alt-7df05b31-alt--
--mixed-7df05b31-mixed
Content-Type: text/plain; name="abc.txt"
Content-Disposition: attachment; filename="abc.txt"
Content-Transfer-Encoding: base64
SEVMTE8gSlVTVCBURVNUSU5HIC4uLiA=
--mixed-7df05b31-mixed--
It may be an artifact from pasting, but try removing the blank space at the end of each boundary. (Highlight the text and you'll notice the boundaries have an extra space, but the closing boundaries-- do not)
Please verify whether your code is look like the following because the following code is working fine for me.
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$headers .= "This is a multi-part message in MIME format.\r\n";
$headers .= "--".$uid."\r\n";
$headers .= "Content-type:text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$headers .= $msg."\r\n\r\n";
$headers .= "--".$uid."\r\n";
$headers .= "Content-Type:application/html; name=\"".$filename."\" \r\n"; // use different content types here
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$headers .= $content."\r\n\r\n";
$headers .= "--".$uid."--";
Don't build your own MIME messages. use Swiftmailer or PHPMailer to do it for you.
Related
I'm using PHP to send out a multipart/mixed message (plain text, html and attachments). However, whilst it works for most accounts, Yahoo, GMail and Sky seem to show blank emails. Where as everything else seems to display the email. ANY HELP WOULD BE GREATLY APPRECIATED!
My headers are
$headers .= "Content-Type: multipart/mixed; boundary=\"mixed-" . $random_hash . "-mixed\"\n";
$headers .= "MIME-Version: 1.0\n";
And the content is;
--mixed-7df05b31-mixed
Content-Type: multipart/alternative; boundary="alt-7df05b31-alt"
--alt-7df05b31-alt
Content-Type: text/plain; charset=utf-8
Hello how are you? I am just checking the mailing function.
Hopefully this will work!
Cheers.
--alt-7df05b31-alt
Content-Type: text/html; charset=utf-8
<div style="font-family:Arial, Helvetica, sans-serif; font-size: 10pt;">
<div>
Hello how are you? I am just <b>checking</b> the mailing function.<br><br>
Hopefully this will work!<br><br>
Cheers.</div></div>
--alt-7df05b31-alt--
--mixed-7df05b31-mixed
Content-Type: text/plain; name="abc.txt"
Content-Disposition: attachment; filename="abc.txt"
Content-Transfer-Encoding: base64
SEVMTE8gSlVTVCBURVNUSU5HIC4uLiA=
--mixed-7df05b31-mixed--
It may be an artifact from pasting, but try removing the blank space at the end of each boundary. (Highlight the text and you'll notice the boundaries have an extra space, but the closing boundaries-- do not)
Please verify whether your code is look like the following because the following code is working fine for me.
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$headers .= "This is a multi-part message in MIME format.\r\n";
$headers .= "--".$uid."\r\n";
$headers .= "Content-type:text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$headers .= $msg."\r\n\r\n";
$headers .= "--".$uid."\r\n";
$headers .= "Content-Type:application/html; name=\"".$filename."\" \r\n"; // use different content types here
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$headers .= $content."\r\n\r\n";
$headers .= "--".$uid."--";
Don't build your own MIME messages. use Swiftmailer or PHPMailer to do it for you.
I've been banging my head on this one for awhile and have been unable to find any helpful articles on my issues. I'm writing a PHP site using the built in mail function for some quick confirmation emails. I realize that there is a fair amount of prejudice against the built in mail function but it has been working well for me up to this point and I would like to be able to continue using it. When I send just a plain text email it all works great, as if I send just a HTML email. However if I try to do a multipart Text/HTML email both versions show up in my email client (tried both thunderbird and gmail). I'm hoping someone here can help me figure out what I'm doing wrong (besides using mail() instead of PHPMail). Here is my code snippet
$uid = md5(uniqid(time()));
$strSubject = "Confirmation for $strEventName on $strEventDate";
$strHTMLMsg = "<h1><center>You are confirmed for the following event:</center></h1><br>\n$strEvenDetails";
$strMsg = strip_tags($strHTMLMsg);
$toEmail = "\"$strName\" <$strEmail>";
$header = "$FromEmail\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\n\n";
$header .= "Content-Transfer-Encoding: 7bit\n";
$header .= "This is a MIME encoded message.\n\n";
$header .= "--".$uid."\n";
$header .= "Content-type:text/plain; charset=UTF-8\n";
$header .= "Content-Transfer-Encoding: 7bit\n\n";
$header .= $strMsg."\n\n";
$header .= "--".$uid."\n";
$header .= "Content-type:text/HTML; charset=UTF-8\n";
$header .= "Content-Transfer-Encoding: 7bit\n\n";
$header .= $strHTMLMsg."\n\n";
$header .= "--".$uid."\n";
$header .= "Content-Type: application/ics; name=\"".$strFileName."\"; method=PUBLISH; charset=UTF-8\n";
$header .= "Content-Transfer-Encoding: 7bit\n";
$header .= "Content-Disposition: attachment; filename=\"".$strFileName."\"\n\n";
$header .= $strICSEvent."\n\n";
$header .= "--".$uid."\n";
$bSuccess = mail($toEmail,$strSubject,"",$header);
Necrobump, but I arrived here after googling, so for others with the same search terms: multipart/mixed implies that you will view all parts. For both HTML and text parts where only one should be visible, use multipart/alternative instead. The last part gets the highest priority.
Also see Mail multipart/alternative vs multipart/mixed for more info, and info about "stacking" mime content.
I need your help!
I have some file that generates a mail with attachment in FPDF and what I need is configure the font family for the mail to Arial and Size 12px, I know how to do that in the PDF but not in the mail.
This is the code for mail with FPDF
$filename = "example.pdf";
// encode data (puts attachment in proper format)
$pdfdoc = $pdf->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));
// main header (multipart mandatory)
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
$headers .= "Content-Transfer-Encoding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;
// message
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$headers .= $message.$eol.$eol;
// attachment
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment".$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= "--".$separator."--";
// send message
mail($to, $subject, "", $headers);
I hope you can help me, thanks !
Email needs to use inline styling, along the following lines:
<p style="font-family: Arial, sans-serif; font-size: 12px">This paragraph is formatted correctly</p>
Or you could put the style into a
<span>Here is lots of stuff.</span>
tag covering the relevant portions inside the
<body></body>
of the email.
I'm not sure why you are not putting $message as the third arg to mail() function. In any case, you will need to play with its content.
I am sending an email which attaches a pdf.
This is the code:
$mpdf->WriteHTML($html);
$content = $mpdf->Output('', 'S');
$content = chunk_split(base64_encode($content));
$mailto = $email;
$from_name = $yourname;
$from_mail = $fromwho;
$replyto = $replyto;
$uid = md5(uniqid(time()));
$subject = 'Horse Details';
$message = 'Please find attached details about the horse medical treatment.';
$filename = 'Horse';
$header = "From: ".$from_name." <".$from_mail.">\r\n";
$header .= "Reply-To: ".$replyto."\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/pdf; name=\"".$filename."\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
$header .= "--".$uid."--";
I would like to add more details in the message and use \r\r for new paragraphs etc.
But for some reason the \r\r or \n will not work? Suspect it is because of some of the header info but not sure which one? Had a bit of a play but could not work it out.
Can you see the problem?
Thank you.
well i don't seem to get it wrong when i sent it , here's the source of the sent message
Subject: Horse Details
From: elibyy Reply-To: test#test.org
MIME-Version: 1.0 Content-Type: multipart/mixed;
boundary="660d0865650c12fa07c8430814690009"
This is a multi-part message in MIME format.
--660d0865650c12fa07c8430814690009 Content-type:text/plain;
charset=iso-8859-1 Content-Transfer-Encoding: 7bit
Please find attached details about the horse medical treatment.
--660d0865650c12fa07c8430814690009 Content-Type: application/pdf;
name="Horse" Content-Transfer-Encoding: base64 Content-Disposition:
attachment; filename="Horse"
--660d0865650c12fa07c8430814690009--
Please find attached details about the horse medical treatment.
I want to format content of the mail to show the content in different line.
here is my message contetn.
bu the \n and \r is not working in this case. it just shows all the content in one line.
$message = 'Thank you for using . We really appreciate your business.'."\r\n".'If you are making your payment by mail, please make the check out to "blah blah" and send it to:'."\n".'blah blah '."\n".'blah blah'."\n".'San Gabriel, CA 91776'."\n".'Please see the attached invoice in PDF format for easy saving & printing purposes.';
$attachment = chunk_split(base64_encode($pdfdoc));
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
$headers .= "Content-Transfer-Encoding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$headers .= $message.$eol.$eol;
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: application/pdf; name=\"".$filename."\"".$eol;
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment".$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= "--".$separator."--";
mail($_POST['add6'],$subject, $message, $headers);
how can i do that?
You're telling the email client the message is HTML, so the CR LF combination will be treated like any other whitespace.
To fix this, change the content type to show you are sending a plain text email
$headers .= "Content-Type: text/plain; charset=\"iso-8859-1\"".$eol;
Alternatively, turn your message into an HTML message - an easy way to do that in your case would be to run it through nl2br to turn the newlines into <br> tags
Yep you've got Content-Type: text/html, so the CR LF is being treated like whitespace. Either send it as Content-Type: text/plain or call nl2br on your contents.
Your content type is HTML so you should use br or p tags instead of line feeds
For \n to work it needs to be double quotes, not single. "\n" is the right thing, '\n' is wrong and will not work.