我的php邮件程序有一些问题,我只收到源代码没有插入。
有人可以检查我的标题吗?
$recipient = str_replace(Array("r","n"),"",$this->to);
$headers = 'From: "xxx.ch" <contact@xxx.ch> '."rn";
$headers .= 'Return-Path: <postmaster@xxx.ch>' . "rn";
if ( isset($this->replyTo) ){
$headers .= 'Reply-To: contact@xxx.ch' . "rn";
}
$random_hash = md5(date('r', time()));
$headers .= "MIME-Version: 1.0 rn Content-Type: multipart/alternative; boundary="".$random_hash.""";
$body = '--'.$random_hash."r".'
Content-Type: text/plain; charset="UTF-8"'."r".'
Content-Transfer-Encoding: 8bit'."r".'
Merci d'utiliser un client mail supportant le format HTML'."r".'
--'.$random_hash."r".'
Content-Type: text/html; charset="UTF-8"'."r".'
Content-Transfer-Encoding: 8bit'."r";
$body .= $this->HTMLBody ."r".'--'.$random_hash.'--';
谢谢
虽然我同意其他评论者的观点,即您应该查看第 3 方库而不是手动执行此操作,但您目前的问题可能与行尾和空格有关,MIME 对此非常挑剔。
您当前有很多这样的代码:
$body = '--'.$random_hash."r".'
Content-Type: text/plain; charset="UTF-8"'."r".'
Content-Transfer-Encoding: 8bit'."r"; // (and so on)
您正在小心地插入回车符("r"
),然后将换行符和大量空格嵌入到下一个单引号字符串中。
相反,您应该只包含回车符,并确保所有其他空格都在单引号之外(您希望 PHP 可读,但不会影响输出):
$body = '--' . $random_hash . "r"
. 'Content-Type: text/plain; charset="UTF-8"'."r"
. 'Content-Transfer-Encoding: 8bit'."r"; // (and so on)