Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Thunderbird未正确显示邮件(php mail())_Php_Email_Attachment_Thunderbird - Fatal编程技术网

Thunderbird未正确显示邮件(php mail())

Thunderbird未正确显示邮件(php mail()),php,email,attachment,thunderbird,Php,Email,Attachment,Thunderbird,我对雷鸟有点意见。我正在尝试从php发送一封包含html版本、纯文本版本和附件的邮件。邮件在Yahoo、Gmail和Roundcube中正确显示,但在Thunderbird中不正确。我希望任何人都能看到问题所在。下面是生成我的邮件的脚本$html=html内容和$plain=纯文本内容 function preparehtmlmail($html, $plain) { preg_match_all('~<img.*?src=.([\/.a-z0-9:_-]+).*?>~si',$h

我对雷鸟有点意见。我正在尝试从php发送一封包含html版本、纯文本版本和附件的邮件。邮件在Yahoo、Gmail和Roundcube中正确显示,但在Thunderbird中不正确。我希望任何人都能看到问题所在。下面是生成我的邮件的脚本$html=html内容和$plain=纯文本内容

function preparehtmlmail($html, $plain) {

preg_match_all('~<img.*?src=.([\/.a-z0-9:_-]+).*?>~si',$html,$matches);
$i = 0;
$paths = array();

foreach ($matches[1] as $img) {
$img_old = $img;

if(strpos($img, "http://") == false) {
  $uri = parse_url($img);
  $paths[$i]['path'] = $_SERVER['DOCUMENT_ROOT'].$uri['path'];
  $content_id = md5($img);
  $html = str_replace($img_old,'cid:'.$content_id,$html);
  $paths[$i++]['cid'] = $content_id;
}
}

$boundary = "--".md5(uniqid(time()));
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/alternative; boundary=\"$boundary\"\n";
$headers .= "From: orders@harliespeed.com\r\n";
$multipart = '';
$multipart .= "--$boundary\n";
$kod = 'utf-8';
$multipart .= "Content-Type: text/plain; charset=$kod\n";
$multipart .= "Content-Transfer-Encoding: Quot-Printed\n\n";
$multipart .= "$plain\n\n";
$multipart .= "--$boundary\n";
$kod = 'utf-8';
$multipart .= "Content-Type: text/html; charset=$kod\n";
$multipart .= "Content-Transfer-Encoding: Quot-Printed\n\n";
$multipart .= "$html\n\n";

foreach ($paths as $path) {
if(file_exists($path['path']))
  $fp = fopen($path['path'],"r");
  if (!$fp)  {
    return false;
  }

$imagetype = substr(strrchr($path['path'], '.' ),1);
$file = fread($fp, filesize($path['path']));
fclose($fp);

$message_part = "";

switch ($imagetype) {
  case 'png':
  case 'PNG':
        $message_part .= "Content-Type: image/png";
        break;
  case 'jpg':
  case 'jpeg':
  case 'JPG':
  case 'JPEG':
        $message_part .= "Content-Type: image/jpeg";
        break;
  case 'gif':
  case 'GIF':
        $message_part .= "Content-Type: image/gif";
        break;
}

$message_part .= "; file_name = \"$path\"\n";
$message_part .= 'Content-ID: <'.$path['cid'].">\n";
$message_part .= "Content-Transfer-Encoding: base64\n";
$message_part .= "Content-Disposition: inline; filename = \"mail_logo.jpg\"\n\n";
$message_part .= chunk_split(base64_encode($file))."\n";
$multipart .= "--$boundary\n".$message_part."\n";

  }

  $multipart .= "--$boundary--\n";
  return array('multipart' => $multipart, 'headers' => $headers);  
函数preparehtmlmail($html,$plain){
preg_match_all('~~si',$html,$matches);
$i=0;
$path=array();
foreach($img与[1]匹配){
$img_old=$img;
if(strpos($img,“http:/”)==false){
$uri=parse_url($img);
$path[$i]['path']=$\u服务器['DOCUMENT\u ROOT'].$uri['path'];
$content\u id=md5($img);
$html=str_replace($img_old,'cid:'。$content_id,$html);
$path[$i++]['cid']=$content\u id;
}
}
$boundary=“-->.md5(uniqid(time()));
$headers.=“MIME版本:1.0\n”;
$headers.=“内容类型:多部分/可选;边界=\”$boundary\“\n”;
$headers.=”来自:orders@harliespeed.com\r\n“;
$multipart='';
$multipart.=“--$boundary\n”;
$kod='utf-8';
$multipart.=“内容类型:文本/普通;字符集=$kod\n”;
$multipart.=“内容传输编码:Quot Printed\n\n”;
$multipart.=“$plain\n\n”;
$multipart.=“--$boundary\n”;
$kod='utf-8';
$multipart.=“内容类型:text/html;字符集=$kod\n”;
$multipart.=“内容传输编码:Quot Printed\n\n”;
$multipart.=“$html\n\n”;
foreach($path作为$path){
如果(文件_存在($path['path']))
$fp=fopen($path['path'],“r”);
如果(!$fp){
返回false;
}
$imagetype=substr(strrchr($path['path'],'.')),1;
$file=fread($fp,filesize($path['path']);
fclose($fp);
$message_part=“”;
开关($imagetype){
案例“png”:
案例“PNG”:
$message_part.=“内容类型:图像/png”;
打破
案件‘jpg’:
案例“jpeg”:
案件‘JPG’:
案例“JPEG”:
$message_part.=“内容类型:图像/jpeg”;
打破
案例“gif”:
案例“GIF”:
$message_part.=“内容类型:image/gif”;
打破
}
$message\u part.=“文件名=\”$path\“\n”;

$message_part.='Content ID:您应该使用多部分MIME部分来正确撰写邮件。一部分用于文本/html版本,另一部分用于html和图像

对于HTML和文本版本,您应该使用multpart/alternative,对于HTML和图像,您应该使用multipart/related。您的电子邮件应该如下所示(为了可读性,我缩进):


您可以使用来生成消息

我只显示图像,不显示文本。我将发布php代码。您真的应该使用或来生成mime消息。它们更易于使用,并且可以将整个脚本减少到大约10行代码(不包括电子邮件本身的内容).回答很好:)还有其他库,比如PHPMailer和Swift-Mailer
Content-Type:multipart/alternative; boundary ---01
  Content-Type:text/plain; boundary ---02
     Your text version content
  ---02
  Content-Type:multipart/related; boundary ---03
     Content-Type:text/html; boundary ---04
       Your HTML version content
     ---04
     Content-Type: image/jpeg; boundary ---05
        Your image content
     ---05
  --- 03
---01