0

PHP Mail error with the message:

530,5.7.0SMTP server error: MAIL FROM command failed Detail: Authentication Required

Following are the key sections of my PHP Script.

new PHPMailer(true)
Host as 'smtp.gmail.com'
SetFrom('MyUsername-Of-Ubuntu-Login@mail.theDomainCreatedInPostfixCOnfiguration.com')
Port=587
SMTPSecure = 'tls'
Username = "one-of-my-gmail-email-id"
Password = "gmail-account-password"
SMTPOptions = array(
  'ssl' => array(
  'cafile' => '/etc/postfix/cacert.pem',
  'verify_peer' => false,
  'verify_peer_name' => false,
  'allow_self_signed' => true
)

As part of my troubleshooting, I did following:

  1. In /etc/mail/sendmail.inc, un-commented the following by removing the prefix "dnl # use /etc/mail/local-host-names

    1. And, I do have list of my host-names in the /etc/mail/local-host-names

    2. executed the command : $ make -C /etc/mail

  2. Edited /etc/postfix/main.cf with following values:

    mydomain = theDomainCreatedInPostfixCOnfiguration.com
    relay_domains = theDomainCreatedInPostfixCOnfiguration.com
    smtpd_sasl_security_options = noanonymous,noplaintext
    mynetworks = 127.0.0.0/8 TheIPaddressOfMyUbuntuMachineWifi
    relayhost = smtp.gmail.com
    myorigin = /etc/mailname
    myhostname = mail.theDomainCreatedInPostfixCOnfiguration.com
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
    
    1. In /etc/mailname, I have mail.theDomainCreatedInPostfixCOnfiguration.com

    2. In /etc/aliases, I have

      root: MyUsername-Of-Ubuntu-Login
      daemon: MyUsername-Of-Ubuntu-Login
      postmaster: MyUsername-Of-Ubuntu-Login
      
    3. I ran command: systemctl reload postfix

    4. I ran command: sudo postmap /etc/aliases , and built aliases.db

Simon Sudler
  • 4,131
Naren
  • 1
  • 1

1 Answers1

0
sudo apt-get install libsasl2-modules

In /etc/postfix/sasl_passwd add these things [Smtp.gmail.com]:587 gmailusername:gmailapppassword

sudo postmap /etc/postfix/sasl_passwd sudo chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db sudo chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db

Add below lines at end of main.cf

enable SASL authentication

smtp_sasl_auth_enable = yes # disallow methods that allow anonymous authentication. smtp_sasl_security_options = noanonymous # where to find sasl_passwd smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd # Enable STARTTLS encryption smtp_use_tls = yes # where to find CA certificates smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

sudo service postfix restart

Hope your issue will resolve