How to send email from PHP with mail()
I was unfortunately put on a project where the entire system was using PHP mail function. I would highly recommend anyone who is reading this to move to PHP Mailer but here are some instructions if you really need them. Firstly I am using XAMPP. This issue fixes error codes:
Must issue a STARTTLS command first
530 5.7.0 Must issue a STARTTLS command first."
SMTP server error: 5.5.1 Authentication Required. Learn more at 530 5.5.1
Start by opening your php.ini file and editing the following:
[mail function]
SMTP = smtp.gmail.com
smtp_port = 25
sendmail_from = email@gmail.com
sendmail_path = "C:\xampp\sendmail\sendmail.exe -t"
Now download the latest Sendmail and go to C:\xampp\sendmail and replace the sendmail.exe and sendmail.ini with the files extracted. Now open the sendmail.ini and replace everything in there with this.
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=email@gmail.com
auth_password= ****
force_sender=email@gmail.com
Now the password was the part I was getting issues with, I tried most peoples recommendations by Allowing less secure apps with gmail, but this seems to have disappeared as of July 2017. What you need to do is authorise an app, select device as Windows and then generate password copy this into the auth_password in sendmail.ini. Try it again and it should work fine now. To help you along you can always look in the debug.log file in C:\xampp\sendmail.
Categories: Posts