我正在尝试使用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 <admin@example.com>';
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 <admin@example.com>';
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 <admin@example.com>' . "\r\n";
mail($to, 'User Registration', $message, $headers);
error_reporting(E_ALL);
ini_set('display_errors', '1');
在页面顶部,并从那里拿走它,如果你仍然无法解决它自己发布在这里,我会尽我所能帮助你.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。