2

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.
root=demo@gmail.com

# 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
AuthUser=demo@gmail.com
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('demo@gmail.com','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 !

Abhishek kamal
  • 432
  • 1
  • 5
  • 13
  • Possible duplicate of [How to send email with SMTP in php](https://stackoverflow.com/questions/25909348/how-to-send-email-with-smtp-in-php) – Prabhjot Singh Kainth Nov 27 '19 at 09:12
  • I don't want to use PHPMailer because [send mail using ssmtp](https://www.nixtutor.com/linux/send-mail-with-gmail-and-ssmtp/) link didn't use PHPMailer and they are able to send mails through localhost without PHPMailer – Abhishek kamal Nov 27 '19 at 10:58
  • [There is usually a different `php.ini` for php/www and php-cli](https://stackoverflow.com/questions/3057110/where-can-i-find-the-php-ini-for-php-cli), have you updated both? – Don't Panic Nov 27 '19 at 11:44
  • I just used PHPMailer [How to send email with SMTP in php](https://stackoverflow.com/questions/25909348/how-to-send-email-with-smtp-in-php) and i write a line `require './src/PHPMailer.php'` in my custom send_mail.php file. But it is giving me error `Uncaught Error: Class 'PHPMailer' not found` – Abhishek kamal Nov 27 '19 at 11:44
  • Alright.. I used PHPMailer and i am getting long error acronym as : `SMTP Error: Could not authenticate. Username and Password not accepted` – Abhishek kamal Nov 27 '19 at 12:09
  • Did you read my comment? Have you checked your php-cli php.ini? – Don't Panic Nov 27 '19 at 12:16
  • @Don'tPanic I have checked. I have updated both but still I am getting same problem. – Abhishek kamal Nov 27 '19 at 12:37

0 Answers0