Can phpmailer send emails through gmail?

WBOY
Release: 2023-03-01 19:08:01
Original
1783 people have browsed it

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

Make sure your gmail account password is correct


It seems that bluehost cannot use gmail

Reply content:

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login

Via smtp POP3 or IMAP protocol

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template