Sending email with PHP on Centos 6.4 and Nginx server -


this question has answer here:

please not mark duplicate issue. have tried recommended steps (checking error logs, checking syntax, header info.. etc..) troubleshoot mod has pointed me , steps did not work. receiving permission issue , can not seem figure out why. error 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 sending email using php on nginx centos 6.4 server. new want first verify if current setup correct , diagnose exact issue before start tweaking config files.

goal: able send users in sql database email alerts, etc.. if have large user-base sending lot of emails..

in php.ini file see..

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

and have used command

/etc/init.d/postfix status 

to verify postfix installed , date (yum -y install postfix, or whatever was)

i looking @ helpful thread ( http://www.webhostingtalk.com/showthread.php?t=1238442 ) , looking follow guide ( http://www.server-world.info/en/note?os=centos_6&p=mail ) again, didnt want start messing stuff until had guidance.

i tried send mail using following code, , visited email.php page on server , did not test email. test email attempted sent , 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, , appreciated. thanks!

solution:

  1. i used commands

    'sudo setsebool -p httpd_can_sendmail 1' , then
    'sudo setsebool -p httpd_can_network_connect 1'

and messages sitting in clientmqueue folder not being sent, looked @ /var/log/maillog , saw message said.. 'centos64 postfix/smtp[22..7]: connect gmail-smtp-in.l.google.com[....]:25: network unreachable' googled error message , read needed install of cyrus plain.. 2. yum install cyrus-sasl-plain

hope helps else out there in same boat.

i giving easy options, cover possible situations.

what following

read old answer way following -- php mail function not working on centos server

self hosted php libraries

this github repo of phpmailer example -- https://github.com/phpmailer/phpmailer second option self hosted email http://swiftmailer.org quite known. follow basic guide , use 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 example mail.');  $result = $mailer->send($message); ?> 

other ways self hosted using pear mail.

transactional email services

instead of self hosting mail server, can use services sendgrid https://sendgrid.com/pricing/ send email on http (we can close mail ports increase security ). there many such services. swiftmailer.org need php library , php snippet hosting email, not server -- https://github.com/sendgrid/sendgrid-php


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -