为什么邮件在php中失败?
这是我的代码:为什么邮件在php中失败?,php,email,Php,Email,这是我的代码: <?php //define the receiver of the email $to = 'dannyfeher69@gmail.com'; //define the subject of the email $subject = 'Test email'; //define the message to be sent. $message = "Hello World!\n\nThis is my mail."; //define the headers we wa
<?php
//define the receiver of the email
$to = 'dannyfeher69@gmail.com';
//define the subject of the email
$subject = 'Test email';
//define the message to be sent.
$message = "Hello World!\n\nThis is my mail.";
//define the headers we want passed.
$header = "From: me@localhost.com";
//send the email
$mail_sent = @mail( $to, $subject, $message);
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
?>
--它返回邮件失败
请帮帮我这有几个原因可能会失败。查找原因的主要障碍是在调用mail()函数之前使用错误控制运算符(@) 其他可能的原因是缺少有效的From标头。尽管您在$header变量中定义了一个,但并没有将其传递给mail()函数。同样重要的是,“发件人”标题是您发送电子邮件的域上的有效电子邮件地址。如果不是这样的话,大多数托管公司现在都会以垃圾邮件的形式拒绝接收电子邮件。您可能还需要为mail()提供第五个参数,该参数通常由一个由-f组成的字符串组成,后跟当前域上的有效电子邮件地址 还有一种可能是,您正试图从自己的计算机发送此信息。mail()函数不支持SMTP身份验证,因此大多数邮件服务器将拒绝来自它们无法识别的来源的邮件 再加上你所有的问题,电子邮件中的换行必须是回车和换行的组合。在PHP中,这是“\r\n”,而不是“\n\n” 假设您使用远程服务器发送邮件,代码应该如下所示:
<?php
//define the receiver of the email
$to = 'dannyfeher69@gmail.com';
//define the subject of the email
$subject = 'Test email';
//define the message to be sent.
$message = "Hello World!\r\nThis is my mail.";
//define the headers we want passed.
$header = "From: me@localhost.com"; // must be a genuine address
//send the email
$mail_sent = mail($to, $subject, $message, $header);
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
?>
删除@
邮件()函数前面的并告诉我们是否显示任何错误/警告。网页位于何处?邮件通过哪个(SMTP-)服务器发送?配置好了吗?谢谢:)我必须配置SMTP