Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP MIME头文件_Php_Email_Mime - Fatal编程技术网

PHP MIME头文件

PHP MIME头文件,php,email,mime,Php,Email,Mime,我的php邮件有一些问题,我只收到源代码,没有解释 有人可以检查我的标题吗 $recipient = str_replace(Array("\r","\n"),"",$this->to); $headers = 'From: "xxx.ch" <contact@xxx.ch> '."\r\n"; $headers .= 'Return-Path: <postmaster@xxx.ch>' . "\r\n"; if ( isset($this->replyTo)

我的php邮件有一些问题,我只收到源代码,没有解释

有人可以检查我的标题吗

$recipient = str_replace(Array("\r","\n"),"",$this->to);
$headers = 'From: "xxx.ch" <contact@xxx.ch> '."\r\n";
$headers .= 'Return-Path: <postmaster@xxx.ch>' . "\r\n";
if ( isset($this->replyTo) ){
    $headers .= 'Reply-To: contact@xxx.ch' . "\r\n";
}
$random_hash = md5(date('r', time()));
$headers .= "MIME-Version: 1.0 \r\n 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.'--';
$recipient=str\u replace(数组(“\r”,“\n”),“,$this->to);
$headers='From:“xxx.ch”。“\r\n”;
$headers.='返回路径:'。“\r\n”;
如果(设置($this->replyTo)){
$headers.='答复:contact@xxx.ch“。”\r\n”;
}
$random_hash=md5(日期('r',时间());
$headers.=“MIME版本:1.0\r\n内容类型:多部分/可选;边界=\”.$random\u hash.\”;
$body='-'.$random\u hash.\r''
内容类型:文本/纯文本;charset=“UTF-8”。“\r”。”
内容传输编码:8位“。\r”
谢谢“使用联合国客户端邮件支持HTML格式”。“\r”。”
--“.$random\u hash。”\r”
内容类型:text/html;charset=“UTF-8”。“\r”。”
内容传输编码:8位“。\r”;
$body.=$this->HTMLBody.\r'-'.$random\u hash'-';

谢谢

虽然我同意其他评论者的观点,即您应该查看第三方库,而不是手工操作,但您当前的问题可能与行尾和空格有关,MIME对此非常挑剔

您当前有许多类似于以下内容的代码:

$body = '--'.$random_hash."\r".' 
         Content-Type: text/plain; charset="UTF-8"'."\r".'
         Content-Transfer-Encoding: 8bit'."\r"; // (and so on)
您小心地插入了回车符(
“\r”
),但随后在下一个单引号字符串中嵌入了换行符和大量空格

相反,您应该包含回车符,并确保所有其他空格都在单引号之外(您希望PHP可读,但不影响输出):


您的服务器是否设置为发送电子邮件?正在运行什么SMTP服务?PHP是否正确配置为发送电子邮件?是的,服务器配置正常,但对于一些旧邮件客户端不支持html,因此我必须添加对它们的支持,现在使用MIME时,我有很多错误:-(您是否考虑过使用PEAR的MIME邮件包而不是手工操作?谢谢您的帮助,但我无法在我的服务器上安装新包…那么,请不要使用PEAR。请使用PHPMailer或类似工具。无论哪种方法,手工编写MIME邮件头,尤其是以黑客方式编写,都不值得您花费时间。
$body = '--' . $random_hash . "\r"
         . 'Content-Type: text/plain; charset="UTF-8"'."\r"
         . 'Content-Transfer-Encoding: 8bit'."\r"; // (and so on)