send PHP mail with Content-Type: multipart/alternative

夙愿已清 提交于 2019-12-01 18:16:56

The line:

$header .= 'Content-type: multipart/alternative;boundary=$boundary '."\n";

Has the wrong quotes, so $boundary won't be expanded. Change to:

$header .= "Content-type: multipart/alternative;boundary=$boundary\n";

And like I said in the comments, in the message headers and the content section headers you should be using \r\n as the line break since that's what is defined in the RFC. Most MTAs will allow simply \n, but some will choke on the message, and some spam filters will count every RFC violation as a point towards your spam score.

Using something like PHPMailer is a much better option because it formats everything perfectly by default, and abides by just about every single obscure, boring RFC.

I think you need quotes around the boundary string.

try this:

$header    .= 'Content-type: multipart/alternative; boundary="' . $boundary . '"\r\n';

Try this example https://github.com/breakermind/PhpMimeParser/blob/master/PhpMimeClient_class.php

$m = new PhpMimeClient();
// Add to
$m->addTo("email@star.ccc", "Albercik");
$m->addTo("adela@music.com", "Adela");
// Add Cc
$m->addCc("zonk@email.au");
// Add Bcc
$m->addBcc("boos@domain.com", "BOSS");    
// Add files inline
$m->addFile('photo.jpg',"zenek123");
// Add file
$m->addFile('sun.png');
// create mime
$m->createMime("Witaj!",'<h1>Witaj jak się masz? <img src="cid:zenek123"> </h1>',"Wesołych świąt życzę!","Heniek Wielki", "hohoho@domain.com");
// get mime
// $m->getMime();
// Show mime
echo nl2br(htmlentities($m->getMime()));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!