1

ついにこれからすべてのバグを取り除いて、今彼らは「ああ、私たちは添付ファイルを追加する必要があるでしょう...」と言いました。メールクライアントに届く添付ファイルがあるので、プレーンテキストバージョンをインラインで表示し、htmlバージョンを別の添付ファイルとして表示してから、ATT00248.txtのような名前の空のように見える93バイトのファイルを表示しています。

誰かが後ろから頭を殴ったり、どこが間違っているのか教えてもらえますか?メールユーザーインターフェイスで使用可能なHTMLインライン、HTMLが使用できないプレーンテキストバージョン、および添付ファイルとしての単一の添付ファイルが必要です。

何か助けはありますか?

<?php
$template = $_SERVER['DOCUMENT_ROOT'] . '/leads/templates/'.$_SESSION['templateFile'];
ob_start();
include($template);
$html = ob_get_contents();
ob_end_clean();

if (strlen($html) == 0) {
    echo "The template at $template did not load.";
    exit;
}

$email   = $_SESSION['user']->email;
$name    = $_SESSION['user']->first_name . ' ' . $_SESSION['user']->last_name;
$from = "$name <$email>";
$subject = unslash($_SESSION['subject']);

$TextMessage =  strip_tags(unslash($_SESSION['message']));

$notice_text = "This is a multi-part message in MIME format.";
$plain_text =  str_replace('&nbsp;',' ', $TextMessage);

if ($_SESSION['attachment']) {
    $fileatt = 'files/' . $_SESSION['attachment'];
    $file = fopen($fileatt,'rb');
    $data = fread($file,filesize($fileatt));
    fclose($file);
    $data = chunk_split(base64_encode($data));
    $mailtype = 'mixed';

    $fileatt_type = "application/octet-stream"; 
    $fileatt_name = $_SESSION['attachment'];
} else {
    $mailtype = 'alternative';
}

$semi_rand = md5(time());
$mime_boundary = "==MULTIPART_BOUNDARY_$semi_rand";
$mime_boundary_header = chr(34) . $mime_boundary . chr(34);

$body = "$notice_text

--$mime_boundary
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

$plain_text

--$mime_boundary
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

$html

--$mime_boundary
";

$body .= "Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Disposition: attachment;\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--$mime_boundary\n";



// #1  //
if ($to = $_SESSION['recipients'][0]) {
    mail($to, $subject, $body,
    "From: " . $from . "\n" .
    "MIME-Version: 1.0\n" .
    "Content-Type: multipart/$mailtype;\n" .
    "     boundary=" . $mime_boundary_header);

    echo "Email sent to " . htmlentities($to) . ".<br />";
}


// #2  //
if ($to = $_SESSION['recipients'][1]) {
    mail($to, $subject, $body,
    "From: " . $from . "\n" .
    "MIME-Version: 1.0\n" .
    "Content-Type: multipart/$mailtype;\n" .
    "     boundary=" . $mime_boundary_header);
    echo "Email sent to " . htmlentities($to) . ".<br />";
}

// #3  //
if ($to = $_SESSION['recipients'][2]) {
    mail($to, $subject, $body,
    "From: " . $from . "\n" .
    "MIME-Version: 1.0\n" .
    "Content-Type: multipart/$mailtype;\n" .
    "     boundary=" . $mime_boundary_header);
    echo "Email sent to " . htmlentities($to) . ".<br />";
}

// #4  //
if ($to = $_SESSION['recipients'][3]) {
    mail($to, $subject, $body,
    "From: " . $from . "\n" .
    "MIME-Version: 1.0\n" .
    "Content-Type: multipart/$mailtype;\n" .
    "     boundary=" . $mime_boundary_header);
    echo "Email sent to " . htmlentities($to) . ".<br />";
}

// #5 //
if ($to = $_SESSION['recipients'][4]) {
    mail($to, $subject, $body,
    "From: " . $from . "\n" .
    "MIME-Version: 1.0\n" .
    "Content-Type: multipart/$mailtype;\n" .
    "     boundary=" . $mime_boundary_header);
    echo "Email sent to " . htmlentities($to) . ".<br />";
}

// CC self?  //
if ($_SESSION['cc_me']) {
    mail($from, $subject, $body,
    "From: " . $from . "\n" .
    "MIME-Version: 1.0\n" .
    "Content-Type: multipart/$mailtype;\n" .
    "     boundary=" . $mime_boundary_header);
    echo "Email sent to " . htmlentities($from) . ".<br />";
}

if ($fileatt) {
    unlink($fileatt);
}

echo "<a href='email_start.php'>Click here</a> to send another email.";
list($_SESSION['email'], $_SESSION['subject'], $_SESSION['bullets'], $_SESSION['message'], 
    $_SESSION['templateFile'], $_SESSION['template'], $_SESSION['cc_me'], $_SESSION['recipients']) = '';
?>
4

2 に答える 2

2

Pekka は正しかった - Swiftmailer を使用するのはシンプルで堅牢でした。http://swiftmailer.org

于 2010-08-23T14:27:39.620 に答える
0

これをコメントとして投稿したいのですが、長すぎます。

// #1  //
if ($to = $_SESSION['recipients'][0]) {
    mail($to, $subject, $body,
    "From: " . $from . "\n" .
    "MIME-Version: 1.0\n" .
    "Content-Type: multipart/$mailtype;\n" .
    "     boundary=" . $mime_boundary_header);

    echo "Email sent to " . htmlentities($to) . ".<br />";
}


// #2  ... #3 ... #4 ... #5

($to = $_SESSION['recipients'][0])常に true になるため、すべてのブロックを実行することになります。また、失敗した場合でも「Email sent to ...」と表示されmail()ます。

あなたが望むものは:

if (in_array($to, $_SESSION['recipients'])) {
    if (mail($to, $subject, $body,
    "From: " . $from . "\n" .
    "MIME-Version: 1.0\n" .
    "Content-Type: multipart/$mailtype;\n" .
    "     boundary=" . $mime_boundary_header)) {
        echo "Email sent to " . htmlentities($to) . ".<br />";
    }
}

または、本当に全員にメールを送信したい場合、または

foreach ($_SESSION['recipients'] as $to ) {
    if (mail($to, $subject, $body,
    "From: " . $from . "\n" .
    "MIME-Version: 1.0\n" .
    "Content-Type: multipart/$mailtype;\n" .
    "     boundary=" . $mime_boundary_header)) {
        echo "Email sent to " . htmlentities($to) . ".<br />";
    }
}
于 2010-08-07T19:41:05.647 に答える