SMTP server response: 530 5.7.0 Must issue a STARTTLS command first
First, make sure you PHP installation has SSL support (look for an "openssl" section in the output from phpinfo()
).
You can set the following settings in your PHP.ini:
ini_set("SMTP","ssl://smtp.gmail.com");
ini_set("smtp_port","465");
How solve this error ( mail(): SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. i2sm7399406pjt.19 - gsmtp )
You're working with SSL
so, check your PHP
installation to make sure you can use that protocol, check if your PHP
supports it.
If it does, try changing your .env
, changing the line MAIL_HOST=smtp.googlemail.com
to MAIL_HOST=smtp.gmail.com
.
If this doesn't solve your problem, try modifying SMTP=ssl
in your php.ini
to SMTP=ssl://smtp.gmail.com
.
SMTP ERROR: MAIL FROM command failed: 530 5.7.0 Must issue a STARTTLS command first when using PHPMailer
To be fair, your script is doing exactly what you're asking it to, but gmail doesn't like that!
Your problems stem from this line:
$mail->Host = gethostbyname('smtp.gmail.com');
This will set Host
to an IP address, and it has been suggested in the past as a workaround for those using IPv6 (which gmail doesn't like), because it always returns an IPv4 address.
However, it causes another problem: there is no longer a host name to verify a certificate against, and TLS connections fail. So this leads you try to turn off TLS:
$mail->SMTPAutoTLS = false;
$mail->SMTPSecure = false;
Having no TLS means you can't authenticate, so you turn that off:
$mail->SMTPAuth = false;
But gmail (very sensibly) won't let you send without authentication, and so you're stuck.
The solution then is to undo all that, revert to the code as provided in the gmail example.
Related Topics
Php: Get the Key from an Array in a Foreach Loop
JSON_Encode Function: Special Characters
Accessing Class Properties with Spaces
Using X-Sendfile with Apache/Php
Get Date Range Between Two Dates Excluding Weekends
Best Way to Get Files from a Dir Filtered by Certain Extension in PHP
Send Cookie with File_Get_Contents
How to Make Number_Format() Not to Round Numbers Up
The Post Method Is Not Supported for This Route. Supported Methods: Get, Head. Laravel
Strip All HTML Tags, Except Allowed
How to Get Rid of MySQL Error 'Prepared Statement Needs to Be Re-Prepared'
Access PHP Variable in JavaScript
PHP Decoding and Encoding JSON with Unicode Characters