0

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' . "\r\n" .
'Reply-To: GMAIL_EMAIL@gmail.com' . "\r\n" .
'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.

Roy Toledo
  • 643
  • 4
  • 20
Retro
  • 113
  • 13
  • So I followed the tutorial here: https://www.digitalocean.com/community/tutorials/how-to-install-postfix-on-centos-6 and it may be the exact same thing as the link posted above, but it allowed me to ensure I had postfix, and cyrus, and then it had me install mailx although I am sure that could be changed at some point. So now the question is, how to send email from that account programmatically. I will try to modify the above code to see if it will send from that email, and if so, then I am in the money! – Retro Nov 13 '16 at 17:14

1 Answers1

0

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

Community
  • 1
  • 1
Abhishek Ghosh
  • 1,161
  • 9
  • 19
  • Abhishek, thanks for your post. So, ideally I would like to be able to check email (some kind of gui/UI to check email and send emails from server) and I would like to also programmatically send email from PHP code. I think what you are saying is that if I want to just send email from PHP code, then using sendmail OR PHPMailer will achieve this. But, IF I want to have an email UI to view emails etc.. then I need to go with something else? If so, what? Thanks – Retro Nov 13 '16 at 18:05
  • I followed your advice and did the following from the article you linked above: 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 – Retro Nov 13 '16 at 19:22
  • [continued] [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 After I did that, I looked at /var/log/maillog and I see this error: – Retro Nov 13 '16 at 19:23
  • 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 ~ – Retro Nov 13 '16 at 19:24
  • Also did this: chgrp smmsp /usr/sbin/sendmail.sendmail chmod a=rx,g+s /usr/sbin/sendmail.sendmail chgrp smmsp /var/spool/mqueue chmod ug=rwx,o= /var/spool/mqueue – Retro Nov 13 '16 at 19:26
  • Tried adding the nginx user to the smmsp group too, and also the root group and got nowhere. I cant figure out for the life of me what the permission error is.. – Retro Nov 13 '16 at 19:27
  • Also to be clear.. I am not trying to send an email from gmail but rather my server. My test code above is likely misleading. – Retro Nov 13 '16 at 20:17
  • Ohh, you are an advanced user. Now I have understood your need. You want to self host mail server, have a web interface, integrate with your PHP app to send mail. No problem. I will write a guide for having self hosted email server with web GUI, with SSL, with security, with whitelisting, with API support, with how to use with PHP scripts to send mail with that app within few days. You'll just follow the guide. Please keep an eye on my blog -- https://thecustomizewindows.com Do not fight with existing one. – Abhishek Ghosh Nov 15 '16 at 23:33