2

この質問の助けを借りて PHP Mail() で添付ファイルを送信しますか? メールの多くの問題を修正しました。Gmail では HTML で表示された画像を含む正しいメールが表示されますが、Thunderbird では画像のみが表示され、HTML は表示されません。メールのソースコードを確認すると、正しいように見えます。

私に何ができる?

$img_src = "km.png"; //about 79KB
$imgbinary = fread(fopen($img_src, "r"), filesize($img_src));
$img_str = base64_encode($imgbinary);

send("name@example.com", "Test Subject", $img_str);

function send($receiver, $subject, $content){

    $header  = "MIME-Version: 1.0" . "\n";
    $header .= "Content-Type: multipart/mixed; boundary=\"aboundary\"" . "\n";

    $header .= "--aboundary". "\n";
    $header .= "Content-Type: multipart/alternative; boundary=\"xboundary\"". "\n\n";

    $header .= "--xboundary". "\n".
                "Content-Type: text/html; charset=utf-8". "\n".
                "Content-Transfer-Encoding: 8bit". "\n";

    $header .= "\n".    
    "<!DOCTYPE html><html><head><meta charset=\"utf-8\"><title></title></head><body>"."\n".
//  "<h1>Hello World</h1><img src=\"cid:0123456789\" alt=\"no img\" /><p>Some Testcontent with umlauts ÖÄÜß</p>". "\n". //this shell work in step 2 as well
    "<h1>Hello World</h1><img src=\"cid:0123456789\" alt=\"no img\" /><p>Some Testcontent without umlauts.</p>". "\n".
    "</body></html>"."\n\n";
    $header .= "--xboundary". "\n".
                "Content-Type: image/png; name=\"att.png\"". "\n".
                "Content-Disposition: inline; filename=\"att.png\"". "\n".
                "Content-Transfer-Encoding: base64". "\n".
                "Content-ID: <0123456789>". "\n".
                "Content-Location: att.png". "\n".
                "\n".
                chunk_split($content, 64).
                "\n".
                "--xboundary--";
    mail($receiver, $subject, "" , $header);
}
4

1 に答える 1

1
    $img_src = "km.png"; //about 79KB
    //$imgbinary = fread(fopen($img_src, "r"), filesize($img_src));
    //$img_str = base64_encode($imgbinary);

    $to= "name@example.com";
    $subject = "Test Subject";



        $headers = "From:  youremail@somewhere.com \r\n";
        $headers .= "Reply-To:  youremail@somewhere.com \r\n";
        $headers .= "MIME-Version: 1.0\r\n";

        $headers .= "Content-Type: text/html" . "\r\n";
        $headers .= "Content-Transfer-Encoding: base64" . "\r\n";

        $message ="<html><head><title></title></head><body><h1>Hello World</h1><img src='".$img_src."' alt='no img' /><p>Some Testcontent with umlauts ÖÄÜß</p>
        <h1>Hello World</h1><img src='".$img_src."' alt='no img' /><p>Some Testcontent without umlauts.</p>
        </body></html>";

        $base64contents = rtrim(chunk_split(base64_encode($message)));             
                     $success = mail($to, $subject, $base64contents, $headers);
                    if (!$success){
                        echo "Something Went Wrong";} 
于 2013-11-19T12:00:13.550 に答える