swdpankaj
swdpankaj

Reputation: 117

SMTP -> ERROR: Failed to connect to server: Connection timed out (110) SMTP Error: Could not connect to SMTP host.

I am using phpmailer to send email. It gives me an error. Here is the code

$mail = new PHPMailer();
    $mail->IsSMTP(); 
    $mail->SMTPDebug  = 2;                     
    $mail->SMTPAuth   = true;                  
    $mail->SMTPSecure = "ssl";                 
    $mail->Host       = "smtp.gmail.com";      
    $mail->Port       = 465;             
    $mail->AddAddress($email);
    $mail->Username="[email protected]";  
    $mail->Password="mypassword";
    $mail->SetFrom('[email protected]','name');
    $mail->AddReplyTo("[email protected]"," name");
    $mail->Subject    = $subject;
    $mail->MsgHTML($message);
    $mail->Send();

Upvotes: 0

Views: 4040

Answers (1)

Sagar Patel
Sagar Patel

Reputation: 461

try with this code

$mail = new PHPMailer(true);
$mail->IsSMTP(); 
$mail->SMTPDebug  = 2;                     
$mail->SMTPAuth   = true;                
$mail->Host       = "ssl://smtp.gmail.com";      
$mail->Port       = 465;             
$mail->AddAddress($email);
$mail->Username="[email protected]";  
$mail->Password="mypassword";
$mail->SetFrom('[email protected]','name');
$mail->AddReplyTo("[email protected]"," name");
$mail->Subject    = $subject;
$mail->MsgHTML($message);
$mail->Send();

Upvotes: 1

Related Questions