dousong3760 2016-11-13 06:05
浏览 58

在Centos 6.4和Nginx服务器上使用PHP发送电子邮件[重复]

This question already has an answer here:

Please do not mark this as a duplicate issue. I have tried the recommended steps (checking error logs, checking syntax, header info.. etc..) to troubleshoot which the mod has pointed me to and all those steps did not work. I am receiving a PERMISSION issue and I can not seem to figure out why. The error I get is:

"Nov 13 14:19:08 centos64 sendmail[6611]: uADJJ80J006611: SYSERR(nginx): queueup: cannot create queue file ./qfuADJJ80J006611, euid=498, fd=-1, fp=0x0: Permission denied ~"

Original Message:

Would like some help with sending email using PHP on a nginx centOS 6.4 server. I am new to this so want to first verify if my current setup is correct and diagnose what the exact issue is before I start tweaking config files.

Goal: I would like to be able to send all the users in my SQL database email alerts, etc.. So eventually if I have a large user-base I could be sending a lot of emails..

In my php.ini file I see..

sendmail_path = /usr/sbin/sendmail -t -i

And I have used command

/etc/init.d/postfix status

to verify that postfix is installed and is also up to date (yum -y install postfix, or whatever it was)

I was looking at this helpful thread ( http://www.webhostingtalk.com/showthread.php?t=1238442 ) and also looking to follow this guide ( http://www.server-world.info/en/note?os=CentOS_6&p=mail ) but again, didnt want to start messing with stuff until I had guidance.

I tried to send mail using the following code, and simply visited the email.php page on my server and did not get my test email. The test email was attempted to be sent from and to a gmail email address.

<?php $to      = 'GMAIL_EMAIL@gmail.com';
$subject = 'Testing';
$message = 'Hello';
$headers = 'From: GMAIL_EMAIL@gmail.com' . "
" .
'Reply-To: GMAIL_EMAIL@gmail.com' . "
" .
'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

As usual, any and all help is appreciated. Thanks!

SOLUTION:

  1. I used commands

sudo setsebool -P httpd_can_sendmail 1

sudo setsebool -P httpd_can_network_connect 1

And then the messages were sitting in the clientmqueue folder not being sent, so I looked at the /var/log/maillog and saw a message that said.. 'centos64 postfix/smtp[22..7]: connect to gmail-smtp-in.l.google.com[....]:25: Network is unreachable' so I googled the error message and read that I needed to do install of cyrus plain..

yum install cyrus-sasl-plain

Hope this helps someone else out there in the same boat.

</div>
  • 写回答

1条回答 默认 最新

  • douai2499 2016-11-13 17:39
    关注

    I am giving some easy options, which probably cover all possible situations.

    What you were following

    Read an old answer for the way you were following -- PHP mail function not working on Centos server

    Self Hosted with PHP Libraries

    This is Github repo of PHPMailer with example -- https://github.com/PHPMailer/PHPMailer Second option for self hosted email http://swiftmailer.org is quite known. Follow their basic guide and use this snippet :

    <?php
    require_once 'swift/lib/swift_required.php';
    
    $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")
      ->setUsername('GMAIL_USERNAME')
      ->setPassword('GMAIL_PASSWORD');
    
    $mailer = Swift_Mailer::newInstance($transport);
    
    $message = Swift_Message::newInstance('Example Subject')
      ->setFrom(array('some@some-mail.com' => 'Example'))
      ->setTo(array('abc@another-mail.com'))
      ->setBody('This is an Example Mail.');
    
    $result = $mailer->send($message);
    ?>
    

    Other ways for self hosted is using Pear Mail.

    Transactional Email Services

    Instead of self hosting mail server, you can use services like SendGrid with https://sendgrid.com/pricing/ to send email over HTTP (we can close mail ports to increase security ). There are many such services. They are exactly like swiftmailer.org you need a PHP library and PHP snippet but they are hosting the email, not your server -- https://github.com/sendgrid/sendgrid-php

    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站