質問

Thunderbirdには少し問題があります。 HTMLバージョンとプレーンテキストバージョンと添付ファイルを使用して、PHPからメールを送信しようとしています。メールはYahoo、Gmail、RoundCubeで適切に表示されますが、Thunderbirdでは適切に表示されません。誰でも問題が何であるかを見ることができることを願っています。これが私のメールを生成するスクリプトです。 $ html = htmlコンテンツと$ plain = 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);  

}

役に立ちましたか?

解決

マルチパートMIMEパーツを使用して、メッセージを正しく作成する必要があります。テキスト/HTMLバージョン用の1つのマルチパート、もう1つはHTMLと画像用のマルチパートです。

HTMLおよびテキストバージョンの場合、MultPart/Alternativeを使用し、HTMLと画像にはMultiPart/関連を使用する必要があります。あなたのメールはこのように好きなはずです(読みやすさのために私はインデント):

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

使用できます 梨::メール メッセージを作成します

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top