PHP mail function not working on Centos server(PHP邮件功能在Centos服务器上不起作用)
问题描述
我正在使用 centos 服务器,必须将邮件发送给用户,所以我从一台服务器复制了我的运行代码并在这里使用它,但它不发送邮件.
I am using centos Server and have to send the mail to the user so i copied running code of mine from one server and used it in here, but it is not sending mails.
代码是:
$to = $email; //writing mail to the user
$subject = "Hii";
$message = "<table>
<tr><td> Hello ".$email.",</td></tr>
<tr><td> Some Text </td></tr>
<tr><td> Some Text </td></tr>
<tr><td> Some Text </td></tr>
<tr><td> Some Text </td></tr>
</table>" ;
$from = "example@domain.com";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "
";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";
// Additional headers
$headers .= 'From: Team <example@domain.com>' . "
";
if(mail($to,$subject,$message,$headers))
{
echo "0";// mail sent Successfully.
}
else
{
echo "1";
}
它总是打印 1.相同的代码在其他项目上运行良好.请指导我在这里也能做些什么来启用它?任何帮助将不胜感激!
It always print 1. Same code running fine on other project. Please guide me what i can do to enable it here too? Any help will be highly appreciated!
推荐答案
安装 sendmail* 并运行以下命令后:
After installing sendmail* and running the following commands:
[root@sendmail ~]# yum install sendmail*
[root@sendmail mail]# yum install dovecot
[root@sendmail mail]# cd /etc/mail/
[root@sendmail mail]# vi local-host-names
# local-host-names - include all aliases for your machine here.
example.com
[root@sendmail mail]# vi /etc/dovecot.conf
protocols = imap pop3 //uncomment
[root@sendmail mail]# m4 sendmail.mc > sendmail.cf
[root@sendmail mail]# make
[root@sendmail mail]# /etc/init.d/sendmail start
[root@sendmail mail]# /etc/init.d/saslauthd start
[root@sendmail mail]# /etc/init.d/dovecot start
[root@sendmail mail]# chkconfig sendmail on
[root@sendmail mail]# chkconfig dovecot on
[root@sendmail mail]# chkconfig saslauthd on
我仍然有同样的问题.我检查了我的 /var/log/maillog
并看到了一个错误:
I still had the same issue. I checked my /var/log/maillog
and saw an error:
My unqualified host name (domain) unknown; sleeping for retry
经过更多搜索,我将 /etc/hosts
从:
After more searching, I changed /etc/hosts
from:
127.0.0.1 localhost localhost.localdomain domain
ip.ip.ip.ip domain localhost
到:
127.0.0.1 localhost.localdomain localhost domain
ip.ip.ip.ip localhost domain
现在邮件功能可以正常工作了.
and now the mail function is now working fine.
这篇关于PHP邮件功能在Centos服务器上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP邮件功能在Centos服务器上不起作用
基础教程推荐
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01