php mail方法_PHP mail()函数不发送电子邮件 墨蓝 2022-11-12 04:17 137阅读 0赞 我正在尝试使用mail()PHP函数发送电子邮件.我一直工作,直到我试图给它一个“用户注册”的主题,然后邮件没有发送! 继承人的代码(大大简化了) $to = $this->post\_data\['register-email'\]; $message = 'Hello etc'; $headers = 'From: noreply@example.com' . "\\r\\n" ; $headers .= 'Content-type: text/html; chareset=iso-8859-1\\r\\n'; $headers .= 'From: Website '; mail($to, 'User Registration', $message, $headers); 我还尝试使用包含文本字符串但不起作用的变量. 为什么在添加主题例外时不发送邮件? 谢谢 编辑:更新的代码仍然无法正常工作 $to = $this->post\_data\['register-email'\]; $message = 'Hello etc'; $headers = 'MIME-Version: 1.0' . "\\r\\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\\r\\n"; $headers .= 'From: Website '; mail($to, 'User Registration', $message, $headers); 解决方法: 在你的第4行,你正在使用’处理它内部的所有内容作为字符串,所以改变 $headers .= 'Content-type: text/html; chareset=iso-8859-1\\r\\n'; 至: $headers .= "Content-type: text/html; charset=iso-8859-1\\r\\n"; 并且正如评论中提到的那样,将chareset更改为charset 编辑: 如果您根据documentation发送txt / html邮件,也在标题中设置mime,那么试试这个 $to = $this->post\_data\['register-email'\]; $message = 'Hello etc'; $headers = 'MIME-Version: 1.0' . "\\r\\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\\r\\n"; $headers .= 'From: Website ' . "\\r\\n"; mail($to, 'User Registration', $message, $headers); 如果它仍然无效,您可以尝试调试代码,只需添加即可 error\_reporting(E\_ALL); ini\_set('display\_errors', '1'); 在页面顶部,并从那里拿走它,如果你仍然无法解决它自己发布在这里,我会尽我所能帮助你. 标签:php,email 来源: https://codeday.me/bug/20191007/1867648.html
还没有评论,来说两句吧...