【发布时间】:2017-12-14 06:42:12
【问题描述】:
我正在开发 PHP mail() 函数。我在 linux 服务器托管的实时站点中创建了一个测试文件。这是我的测试文件的样子
test.php
<?php
ini_set('SMTP','smtp.mydomain.com');
ini_set('smtp_port',25);
$to = 'xyz@gmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: abc@gmail.com' . "\r\n" .
'Reply-To: abc@gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers)){
echo 'Successfully sent';
}
else {
echo 'failed';
}
?>
但我没有收到任何邮件。它总是显示failed。
有什么遗漏吗?
我检查了解决方案,但仍然无法正常工作
更新:
<?php
if ( function_exists( 'mail' ) )
{
echo 'mail() is available';
}
else
{
echo 'mail() has been disabled';
}
error_reporting(E_ALL);
ini_set('display_errors', '1');
$to = 'xyz@gmail.com';
$subject = 'the subject';
$message = 'hello';
if(mail($to, $subject, $message, "From:abc@mydomain.in")){
echo 'Successfully sent';
}
else {
print_r(error_get_last());
echo ' failed';
}
?>
输出:
mail() is available failed
【问题讨论】:
-
尝试先发送不带任何标题的邮件,例如 mail($to,$subject,$message,"From: existingemail@gmail.com");
-
确保 $to 和 $from 电子邮件 ID 存在。在 From 中,如果您可以包含您的域电子邮件,例如 info@example.com,那就更好了
-
不需要给 ini_set('SMTP','smtp.mydomain.com'); ini_set('smtp_port',25);
-
首先确保您的电子邮件在您的服务器中使用 PHP 的邮件功能。否则你也可以使用 phpmailer 类来发送邮件。
-
@AmitGupta 尝试了一切,但还是一样