Home >Backend Development >PHP Tutorial >Can phpmailer send emails through gmail?
How to send a letter through gmail?
I use a virtual host (BLUEHOST) and apply for its built-in email service. Then I can send emails by adding phpmailer.
It’s just that I wanted to change to send the letter through gmail
So it failed
I refer here: http://stackoverflow.com/ques...
<code>$mail = new PHPMailer(); $mail->IsSMTP(); // enable SMTP $mail->SMTPDebug = 1; $mail->SMTPAuth = true; $mail->SMTPSecure = 'ssl'; $mail->Host = "smtp.gmail.com"; $mail->Port = 465; $mail->IsHTML(true); $mail->Username = "***@gmail.com"; $mail->Password = "***"; $mail->SetFrom("***@gmail.com"); $mail->Subject = "Test"; $mail->Body = "hello"; $mail->AddAddress("xxxxxxxx@gmail.com"); if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message has been sent"; }</code>
Error that pops up
<code>SMTP -> ERROR: Failed to connect to server: Connection timed out (110) The following From address failed: ***@gmail.com : Called Mail() without being connected Mailer Error: The following From address failed: ***@gmail.com : Called Mail() without being connected</code>
Make sure your gmail account password is correct
It seems that bluehost cannot use gmail
How to send a letter through gmail?
I use a virtual host (BLUEHOST) and apply for its built-in email service. Then I can send emails by adding phpmailer.
It’s just that I wanted to change to send the letter through gmail
So it failed
I refer here: http://stackoverflow.com/ques...
<code>$mail = new PHPMailer(); $mail->IsSMTP(); // enable SMTP $mail->SMTPDebug = 1; $mail->SMTPAuth = true; $mail->SMTPSecure = 'ssl'; $mail->Host = "smtp.gmail.com"; $mail->Port = 465; $mail->IsHTML(true); $mail->Username = "***@gmail.com"; $mail->Password = "***"; $mail->SetFrom("***@gmail.com"); $mail->Subject = "Test"; $mail->Body = "hello"; $mail->AddAddress("xxxxxxxx@gmail.com"); if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message has been sent"; }</code>
Error that pops up
<code>SMTP -> ERROR: Failed to connect to server: Connection timed out (110) The following From address failed: ***@gmail.com : Called Mail() without being connected Mailer Error: The following From address failed: ***@gmail.com : Called Mail() without being connected</code>
Make sure your gmail account password is correct
It seems that bluehost cannot use gmail
It prompts that the connection has timed out. Where is the host? Can I access Google services?
First test it locally with your code to see if there are any problems. If there are no problems, then consult the web hosting provider.
Judging from the error message, it is very likely that the network of the server where the code is located cannot access the Gmail mail server at all.
<code>没连接到`$mail->Host = "smtp.gmail.com";`</code>
Via smtp POP3 or IMAP protocol