[英]php mail() function not working in linux server
I'm working on PHP mail() function.我正在研究 PHP mail() 函数。 I have created a test file in my live site hosted in linux server.
我在 linux 服务器中托管的实时站点中创建了一个测试文件。 This is my test file looks like
这是我的测试文件看起来像
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';
}
?>
But I didn't receive any mail.但是我没有收到任何邮件。 It always shows
failed
.它总是显示
failed
。
Is there anything missing?有什么遗漏吗?
I checked for a solution, but still its not working我检查了一个解决方案,但仍然无法正常工作
UPDATE :更新 :
<?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';
}
?>
OUTPUT :输出 :
mail() is available failed
Try to run this and restart apache2尝试运行它并重新启动 apache2
sudo apt-get install sendmail sudo sendmailconfig (answer Yes to everything) sudo service apache2 restart sudo apt-get install sendmail sudo sendmailconfig(对一切都回答是)sudo service apache2 restart
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.