加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

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

发布时间:2020-05-31 15:55:55 所属栏目:PHP 来源:互联网
导读:我使用centos服务器,并且必须发送邮件给用户,所以我从一个服务器复制我的运行代码,并在这里使用它,但它不发送邮件. 代码是: $to = $email; //writing mail to the user $subject = Hii; $message = table trtd

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

                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

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

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读