How do I use ssmtp for sending mail in php?

2.9k Views Asked by At

I am using Ubuntu 19.10. I have just installed ssmtp and reconfigured the file /etc/ssmtp/ssmtp.conf as given in https://www.nixtutor.com/linux/send-mail-with-gmail-and-ssmtp/

So my /etc/ssmtp/ssmtp.conf looks like -

# Make this empty to disable rewriting.
[email protected]

# The place where the mail goes. The actual machine name is required no 
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.gmail.com:587
# Where will the mail seem to come from?
#rewriteDomain=

# The full hostname
hostname=127.0.1.1:80
UseSTARTTLS=YES
[email protected]
AuthPass=123456

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES

Mail path in php.ini
sendmail_path /usr/sbin/sendmail -t -i

and custom php script send_mail.php for send mail -

<?php
  // the message
  $msg = 'Testing for send mail in Linux';
  // send email
  $send = mail('[email protected]','My subject',$msg);
  echo $send ?  'MAIL SENT' : 'MAIL NOT SENT';
?>

OUTPUT when running through browser
MAIL NOT SENT
OUTPUT when running through terminal (php send_mail.php)
sendmail: (127.0.1.1:80)
MAIL NOT SENT

Help me please !

0

There are 0 best solutions below