PHP邮件功能在Centos服务器上不起作用 [英] PHP mail function not working on Centos server

查看:19
本文介绍了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服务器上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆