PHP邮件在Gmail中打开,但在Outlook中不打开

时间:2013-03-21 01:27:29

标签: email outlook gmail php

当我使用PHP发送邮件时,它在Gmail中显示正确但在Outlook中不显示。这是一封带有PDF附件和一些文字的邮件。 PDF是使用fpdf创建的,并作为附件发送,这在Gmail和Outlook中运行良好。

唯一的问题是,在Gmail中,电子邮件的文本显示正确,在Outlook中它只是一个空白页面,文本是一个额外的附件。

这是我的代码:

// encode data 
$pdfdoc = $pdf->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));

// email stuff (change data below)
$to = $contactEmail; 
$from = $myEmail; 
$subject = "MySubjectHere"; 
$message = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
            "http://www.w3.org/TR/html4/loose.dtd">
            <html><head></head><body>
            <p>Hi '$contactName.',</p><br>
            <p>Please find your pdf attached per your request.</p>
            <p>Feel free to call or email if you have any questions.</p>
            <p>Kind regards,</p><br>
            <p>MyNameHere</p>
            <p><strong>Manager</strong></p>
            <img alt="image" src="http://LinkToImage.png"/>
            <p style="color:#76923c;">
            <strong>P:</strong> 01 2345 6789| 
            <strong>W:</strong> <a href="http://www.example.com" target="_blank">www.example.com</a></p>
            <p style="color:#76923c;">
            <strong>A:</strong> 94 Test Street. 
            </p></body></html>';

// a random hash will be necessary to send mixed content
$separator = md5(time());

// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;

// attachment name
$filename = $id."_".str_replace(" ","_",$Name).'.pdf';

// main header
$headers  = "From: ".$from.$eol;
$headers .= "Bcc: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol; 
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";

// no more headers after this, we start the body! //

$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;

// message
$body .= "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= $message.$eol;

// attachment
$body .= "--".$separator.$eol;
$body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol; 
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment".$eol.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";

// send message
mail($to, $subject, $body, $headers);

3 个答案:

答案 0 :(得分:2)

我发现它出了问题:

 $body .= $message.$eol;

应该是

 $body .= $message.$eol.$eol;

最后在3天后找到它! 无论如何,感谢您的回复!

答案 1 :(得分:0)

$to = $contactEmail; 
$from = $myEmail; 
$boundary = md5(date('r', time()));
$msg  = "This is a multi-part message in MIME format.\n\n";
$msg .= "--$boundary\n";
$msg .= "Content-Type: text/html; charset=utf-8; format=flowed; delsp=yes\n";
$msg .= "Content-Transfer-Encoding: 7bit\n\n";
$msg .= "<h1>Website Enquiry</h1>
            <p><strong>Name:</strong> $name<br />
            <strong>Email:</strong> $email<br />
            <strong>Phone:</strong> $phone<br />
            <strong>Subject Name:</strong> $subject<br />
            <strong>Question:</strong> $question</p>";

$e_headers = "From: " . $from . "\n";
$e_headers .= "MIME-Version: 1.0\n";
$e_headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\n";

mail($to, $subject, $msg, $e_headers);

这是我用于HTML联系表单的代码。 您不需要通过PHP_EOL传递内容,只需传递附件

答案 2 :(得分:0)

console.log(+32)