尽管将php.ini配置为有效的send_from地址,但我收到此错误。我知道它是有效的,因为当我从松鼠邮件发送它时它起作用但是当用php发送邮件时它将无效。无效地址可能是指send_from地址。所以我看不出它怎么会认为这是错的。这是php代码:
$email="tobiasvogel1@googlemail.com";
$subject = "Your New Password";
$from="admin@dayshare.local";
$message = "Your new password is as follows:
xxxxxxxxxxxxxxxxxxxxxxxxxxx
This email was automatically generated.";
if(!mail($email, $subject,$message,$from)){
echo ("error");
}else echo "success";
并在php.ini中:
SMTP = localhost
sendmail_from = admin@dayshare.local
答案 0 :(得分:4)
550此地址不允许递送
此错误表示发件人正在尝试向其发送电子邮件 他不被允许发送的地址。生成此消息 在hMailServer检查了IP范围设置之后。举个例子, 默认IP范围配置不允许外部用户访问 向其他外部用户发送消息。这是为了防止人们 使用您的服务器发送垃圾邮件。因此,如果外部用户尝试发送 发给另一个外部用户的消息,他会收到此消息。
这就是你得到的错误的含义。这来自hMailServer Documentation。
你可以尝试以下方法吗?
<?php
mail('tobiasvogel1@googlemail.com','Test Email','This is a test email.',"From: tobiasvogel1@googlemail.com");
?>
如果它不起作用,那么可能是由于您的hMailServer配置错误,您需要检查hMailServer Logs。
答案 1 :(得分:2)
mail()函数的第4个参数不是“from”。在您的代码中,您只传递没有“发件人:”的电子邮件地址 - 第四个参数用于其他邮件标题,因此您必须将其格式化为:
mail($email, $subject,$message,"From: admin@dayshare.local\r\nX-Mailer: PHP");
我添加了另一个标题作为示例。
答案 2 :(得分:2)
试试这个,为我工作:
ini_set("sendmail_from", "info@yourdomain.com");
答案 3 :(得分:0)
你需要引号和分号:
$email="tobiasvogel1@googlemail.com";
答案 4 :(得分:0)
在更改php.ini后,每次都要保持心情,
P.S。在php.ini中,我使用过:
SMTP = localhost
smtp_port = 25
sendmail_from = your_user@gmail.com
或者如果oyu无法编辑php.ini,请尝试在php脚本中插入这些行。
ini_set("SMTP", "localhost");
ini_set("smtp_port", "25");
ini_set("sendmail_from", "your_user@gmail.com");