IsSMTP();$mail->CharSet=”UTF-8″;$mail->SMTPSecure = “tls”;$mail->Host = “smtp.gmail.com”;$mail->Port = 587;$mail->Username = “MyUsername
gmail.com”, “Information”);$mail->IsHTML(true);$mail->Subject = “PHPMailer Test Subject via Sendmail, basic”;$mail->AltBody = “To view the message, please use an HTML compatible email viewer!”;$mail->Body = “Hello”;if(!$mail->Send()){ echo “Mailer Error: ” . $mail->ErrorInfo;}else{ echo “Message sent!”;}?>but I receive this following error
Mailer Error: SMTP Error: The following recipients failed: anotherValidGmail
gmail.comSMTP server error: SMTP AUTH is required for message submission on port 587my domain is vatandesign.ir
Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
$mail = new PHPMailer(); // create a new object$mail->IsSMTP(); // enable SMTP$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only$mail->SMTPAuth = true; // authentication enabled$mail->SMTPSecure = “ssl”; // secure transfer enabled REQUIRED for Gmail$mail->Host = “smtp.gmail.com”;$mail->Port = 465; // or 587$mail->IsHTML(true);$mail->Username = “email
gmail.com”); if(!$mail->Send()) { echo “Mailer Error: ” . $mail->ErrorInfo; } else { echo “Message has been sent”; }This code above has been tested and worked for me.
Đang xem: Send email in php using gmail smtp
It could be that you needed $mail->SMTPSecure = “ssl”;
Also make sure you don”t have two step verification switched on for that account as that can cause problems also.
UPDATED
You could try changing $mail->SMTP to:
$mail->SMTPSecure = “tls”;It”s worth noting that some SMTP servers block connections.Some SMTP servers don”t support SSL (or TLS) connections.
Share
Improve this answer
Follow
edited Nov 23, 2015 at 17:09
answered Apr 16, 2013 at 22:45
andrew-caulfieldandrew-caulfield
2,06022 gold badges2323 silver badges2424 bronze badges
6
| Show 1 more comment
33
So I just solved my own “SMTP connection failure” error and I wanted to post the solution just in case it helps anyone else.
I used the EXACT code given in the PHPMailer example gmail.phps file. It worked simply while I was using MAMP and then I got the SMTP connection error once I moved it on to my personal server.
All of the Stack Overflow answers I read, and all of the troubleshooting documentation from PHPMailer said that it wasn”t an issue with PHPMailer. That it was a settings issue on the server side. I tried different ports (587, 465, 25), I tried “SSL” and “TLS” encryption. I checked that openssl was enabled in my php.ini file. I checked that there wasn”t a firewall issue. Everything checked out, and still nothing.
The solution was that I had to remove this line:
$mail->isSMTP();Now it all works. I don”t know why, but it works. The rest of my code is copied and pasted from the PHPMailer example file.
Share
Improve this answer
Follow
answered Jul 2, 2015 at 21:12
Evan ButlerEvan Butler
62911 gold badge66 silver badges1313 bronze badges
8
| Show 3 more comments
8
Also worth noting that if you have two factor authentication enabled, you”ll need to setup an application specific password to use in place of your email account”s password.
You can generate an application specific password by following these instructions:https://support.google.com/accounts/answer/185833
Then set $mail->Password to your application specific password.
Xem thêm: Khi Nào Nên Cho Bé Bú Mẹ Đến Mấy Tháng Tuổi? Cho Con Bú Mẹ Đến Khi Nào Là Hợp Lý
Share
Improve this answer
Follow
answered Jan 22, 2014 at 12:05
Tim CarrTim Carr
75766 silver badges44 bronze badges
Add a comment |
5
It seems that your server fails to establish a connection to Gmail SMTP server.Here are some hints to troubleshoot this:1) check if SSL correctly configured on your PHP (module that handle it isn”t installed by default on PHP. You have to check your configuration in phph.ini).2) check if your firewall let outgoing calls to the required port (here 465 or 587). Use telnet to do so. If the port isn”t opened, you”ll then require some support from sysdmin to setup the config.I hope you”ll sort this out quickly!
Share
Improve this answer
Follow
answered Jul 26, 2013 at 8:26
Pr ShadokoPr Shadoko
1,64922 gold badges1515 silver badges1616 bronze badges
Add a comment |
5
Open this Link and select follow the instructions google servers blocks any attempts from unknown servers so once you click on captcha check every thing will be fine
Share
Improve this answer
Follow
answered Oct 7, 2013 at 9:56
Yasin HassanienYasin Hassanien
3,96611 gold badge2020 silver badges1616 bronze badges
4
Add a comment |
1
Google treat Gmail accounts differently depending on the available user information, probably to curb spammers.
I couldn”t use SMTP until I did the phone verification. Made another account to double check and I was able to confirm it.
Share
Improve this answer
Follow
answered Apr 19, 2016 at 15:29
Forgot My Login 12Forgot My Login 12
1111 bronze badge
Add a comment |
1
this code working fine for me
$mail = new PHPMailer; //Enable SMTP debugging. $mail->SMTPDebug = 0; //Set PHPMailer to use SMTP. $mail->isSMTP(); //Set SMTP host name $mail->Host = $hostname; //Set this to true if SMTP host requires authentication to send email $mail->SMTPAuth = true; //Provide username and password $mail->Username = $sender; $mail->Password = $mail_password; //If SMTP requires TLS encryption then set it $mail->SMTPSecure = “ssl”; //Set TCP port to connect to $mail->Port = 465; $mail->From = $sender; $mail->FromName = $sender_name; $mail->addAddress($to); $mail->isHTML(true); $mail->Subject = $Subject; $mail->Body = $Body; $mail->AltBody = “This is the plain text version of the email content”; if (!$mail->send()) { echo “Mailer Error: ” . $mail->ErrorInfo; } else { echo “Mail Sent Successfully”; }
Share
Improve this answer
Follow
edited Oct 27, 2016 at 5:47
answered Oct 27, 2016 at 5:41
Zohaib HussainZohaib Hussain
1122 bronze badges
2
Add a comment |
0
$mail->SMTPOptions = array( “ssl” => array( “verify_peer” => false, “verify_peer_name” => false, “allow_self_signed” => true ) );
Share
Improve this answer
Follow
answered Mar 29, 2018 at 4:17
brandenMbrandenM
2922 bronze badges
2
Add a comment |
0
If you are using cPanel you should just click the wee box that allows you to send to external servers by SMTP.
Login to CPanel > Tweak Settings > All> “Restrict outgoing SMTP to root, exim, and mailman (FKA SMTP Tweak)”
As answered here:
“Password not accepted from server: 535 Incorrect authentication data” when sending with GMail and phpMailer
Share
Improve this answer
Follow
edited Mar 21, 2019 at 13:49
Shahzad Barkati
2,52466 gold badges2323 silver badges3232 bronze badges
answered Oct 26, 2017 at 15:32
TristanisgingerTristanisginger
1,75233 gold badges2424 silver badges3838 bronze badges
Add a comment |
0
Anderscc has got it correct. Thanks. It worked for me but not 100%.
I had to set
$mail->SMTPDebug = 0;Setting it to 1, can cause errors especially if you are passing some data as json to next page. Example – Performing verification if mail is sent, using json to pass data through ajax.
I had to lower my gmail account security settings to get rid of errors:” SMTP connect() failed ” and ” SMTP ERROR: Password command failed “
Solution:This problem can be caused by either “less secure” applications trying to use the email account (this is according to google help, not sure how they judge what is secure and what is not) OR if you are trying to login several time in a row OR if you change countries (for example use VPN, move code to different server or actually try to login from different part of the world).
Links that fix the problem (you must be logged into google account):
view recent attempts to use the account and accept suspicious access.
Xem thêm: Cách Kê Gối Sau Khi Quan Hệ, Bật Mí Cách Kê Gối Để Dễ Thụ Thai Nhất
Note:You can go to the following darkedeneurope.com answer link for more detailed reference.