PHP邮件功能不能在Centos服务器上工作

前端之家收集整理的这篇文章主要介绍了PHP邮件功能不能在Centos服务器上工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用centos服务器,并且必须发送邮件用户,所以我从一个服务器复制我的运行代码,并在这里使用它,但它不发送邮件.

代码是:

$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' . "\r\n";
                    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
                // Additional headers
                $headers .= 'From: Team <example@domain.com>' . "\r\n";

                if(mail($to,$subject,$message,$headers))
                {
                    echo "0";// mail sent Successfully.
                }
                else
                {
                    echo "1";
                }

它总是打印1.相同的代码在其他项目上运行良好.请指导我,我可以做什么来启用它在这里?
任何帮助将高度赞赏!

安装sendmail *并运行以下命令后:
[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并看到一个错误

My unqualified host name (domain) unknown; sleeping for retry

经过更多的搜索,我更改了/ etc / hosts从:

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

现在邮件功能现在正常工作.

猜你在找的PHP相关文章