When I send an email using PHP to hotmail or to my personal email, it comes through fine. The message and PDF attachment is there.
When I send the same email to a google gmail account, the headers and subject seem to be intact, but there is no message and the attachment shows up as noname with a size of 0.
I've found mention of this in other forums but nothing I've tried has worked. In fact, some of the things I've tried end up breaking the email when it goes to hotmail.
Has anybody encountered this and solved it? Here's a condensed version of my code - Thanks for any ideas you might have!!
$to = 'name@gmail.com';
$subject = 'Quote';
$random_hash = md5(date('r', time()));
$headers = "From: Me <email@company.com>\nReply-To: Me <email@company.com>";
$headers .= "\nCC: Me <email@company.com>";
$headers .= "\nReturn-Path: Me <email@company.com>";
$headers .= "\nMIME-Version: 1.0";
$headers .= "\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
//read the attachment file contents into a string,
//encode it with MIME base64,
//and split it into smaller chunks
$attachment = chunk_split(base64_encode(file_get_contents($PDFOutputFile)));
//define the body of the message.
ob_start(); //Turn on output buffering
?>
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Thank you for requesting a quote. I look forward to working with you on your project!
Sincerely,
me
-----------------------------------------------
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<p>Thank you for requesting a quote. I look forward to working with you on your project!</p>
<p>Sincerely, <br>
me
-----------------------------------------------</p>
--PHP-alt-<?php echo $random_hash; ?>--
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: application/pdf; name="Quote <?php echo $PDFfilename; ?>"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
<?php echo $attachment; ?>
--PHP-mixed-<?php echo $random_hash; ?>--
<?php
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "<h2>Quote sent to <i>" . $to . "</i></h2>" : "Mail failed";