php e-mail senden mit Anhang

Ich kann nicht scheinen, um herauszufinden, das problem mit dieser php-Funktion, die ich schrieb, sollten senden Sie eine e-mail mit attachment. Ich habe gekämpft, mit ihm für eine Weile.

function myMail($to, $subject, $mail_msg, $filename, $contentType){

    $random_hash = md5(date('r', time()));
    $headers = "From: [email protected]\r\nReply-To: ".$to;
    $headers .= "\r\nContent-Type: ".$contentType.
        "; boundary=\"PHP-mixed-".$random_hash."\"";

    $attachment = chunk_split(base64_encode(file_get_contents($filename)));
    ob_start();

    echo "
--PHP-mixed-$random_hash
Content-Type: multipart/alternative; boundary=\"PHP-alt-$random_hash\"

--PHP-alt-$random_hash
Content-Type: text/plain; charset=\"utf-8\"
Content-Transfer-Encoding: 7bit

$mail_msg

--PHP-alt-$random_hash

--PHP-mixed-$random_hash--
Content-Type: text/plain; name=\"$filename\" 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 

$attachment
--PHP-mixed-$random_hash--
";
    $message = ob_get_clean();
    $mail_sent = @mail( $to, $subject, $message, $headers );
    return $mail_sent ? "Mail sent" : "Mail failed";
}

Bearbeiten Das problem ist, dass die Nachricht der E-mail, gemischt mit der Datei, und senden Sie als Anlage.

Sie sagen nicht, was nicht funktioniert.
Die gesamte Ausgabe, die überschriften enthalten (minus base64-codierte Datei)

InformationsquelleAutor Valentin Brasso | 2010-06-22

Schreibe einen Kommentar