PHP邮件()在移动设备上格式不正确

时间:2018-02-24 11:01:31

标签: php html-email

我使用PHP mail()函数发送带附件的电子邮件。这很奇怪,但在我的电脑上,我可以看到带有附件的格式正确的HTML电子邮件。当我在三星手机上收到相同的电子邮件时,如下图所示 screenshot

此代码:

ob_start();
?>
--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/html; charset="utf-8" 
Content-Transfer-Encoding: 7bit
<html>
.....html goes here
</html>

上面的代码是在移动设备上打印的,应该附加的文件是base64编码但没有附加

这是我的自定义邮件功能的样子:

function send_mail_with_attachement($p){
$headers ='';
if(isset($p['from_name'])) $headers .= "From: =?utf-8?b?".base64_encode($p['from_name'])."?= <".$p['from_email'].">\r\n";
if(isset($p['from_email'])) $headers .= "Reply-To: ". strip_tags($p['from_email']) . "\r\n";
if(!empty($p['cc'])) $headers .= "CC: ". strip_tags($p['cc']) . "\r\n";
if(!empty($p['bcc'])) $headers .= "BCC: ". strip_tags($p['bcc']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";

$random_hash = md5(date('r', time()));
$headers .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\""; 
$attachment = chunk_split(base64_encode(file_get_contents($_FILES["myfiles"]["tmp_name"]))); 
ob_start();
?>
--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/html; charset="utf-8" 
Content-Transfer-Encoding: 7bit

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><?php echo $p['subject'];?></title>
</head>
<body bgcolor="White">
<center>
<div style="font-size:12px;width:620px;padding:5px;margin:0;color:#555;background:#fff;">
<a style="display:block;text-decoration:none;margin:0;padding:0;" href="<?php echo WebSite;?>" target="_blank">
<img style="padding:0;margin:0;border:none;width:100%;" border="0" src="<?php echo WebSite;?>/images/mailheader.jpg" alt="<?php echo official_site_name;?>" />
<div style="background:#cd1718;color:#fff;font-size:11pt;font-weight:700;font-style:italic;margin:0;padding:5px 0;" align="center"><?php echo official_site_name;?></div>
</a>
<div style="padding:5px;text-align:left;font-size:13px;font-family:verdana;"><br><?php echo $p['body'];?><br></div>
<div style="background:#cd1718;color:#fff;margin:0;padding:5px 0;text-align:center;">©Copyright <?php echo date('Y');?>"&nbsp;&nbsp;<a href="<?php echo WebSite;?>" target="_blank" style="color:#fff;text-decoration:none;"><?php echo official_site_name;?></a> - All Rights Reserved</div>
</div>
</center>
</body>
</html>


--PHP-alt-<?php echo $random_hash; ?>-- 

--PHP-mixed-<?php echo $random_hash; ?>  
Content-Type: application/zip; name="<?php echo $_FILES['myfiles']['name'];?>"  
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 
$body = ob_get_clean();


$mail_sent = mail($p['to'], '=?utf-8?B?'.base64_encode(strip_tags($p['subject'])).'?=', $body, $headers);
return $mail_sent ? true : false;
}

在电脑和手机上出现这种差异的原因可能是什么?

感谢您的帮助

0 个答案:

没有答案