HTML-Teil der Nachricht wird ignoriert, wenn eine E-Mail mit Anhang mit Mail () im Cron-Job gesendet wirdPhp

PHP-Programmierer chatten hier
Anonymous
 HTML-Teil der Nachricht wird ignoriert, wenn eine E-Mail mit Anhang mit Mail () im Cron-Job gesendet wird

Post by Anonymous »

Ich sende eine E-Mail per Cron-Job. Der Anhang funktioniert und wird der E-Mail-Nachricht hinzugefügt. Der mit $ body2 < /code> verwiesene HTML -Teil kommt jedoch nicht durch.
Der Code sieht folgt aus: < /p>
$body2 = '...';
$email = '[email protected]';
$attachment = '/path/to/file/file.txt';
$content = file_get_contents($attachment);

$prefix = "part_"; // This is an optional prefix
$boundary = uniqid($prefix, true);

// headers
$headers = implode("\r\n", [
'From: [email protected]',
'Reply-To: [email protected]',
'X-Mailer: PHP/' . PHP_VERSION,
'MIME-Version: 1.0',
// boundary parameter required, must be enclosed by quotes
'Content-Type: multipart/mixed; boundary="' . $boundary . '"',
'Content-Transfer-Encoding: BINARY',
'This is a MIME encoded message.' // message for restricted transports
]);

// message and attachment
$message = implode("\r\n", [
"--" . $boundary, // header boundary delimiter line
//'MIME-Version: 1.0',
'Content-Type: text/html; charset="utf8"',
'Content-Transfer-Encoding: 8bit',
//$body2 holds the html part of the e-mail
$body2,
'--' . $boundary, // content boundary delimiter line
'Content-Type: application/octet-stream; name="file.txt"',
'Content-Transfer-Encoding: BINARY',
'Content-Disposition: attachment',
$content,
"--" . $boundary . "--" // closing boundary delimiter line
]);

mail($email, $subject, $message, $headers); // send the email
< /code>
Ich habe Stunden damit verbracht, dies zu konfigurieren. Ich habe auch einen einfachen Text mit dem gleichen Ergebnis ausprobiert. Der Text sowie der HTML-Gewinn werden in der E-Mail-Nachricht nicht angezeigt. Wie muss ich das einrichten, dass die HTML und der Anhang durchkommen? Danke für einen Hinweis.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post