SMTP connect failed PHPmailer - PHP

0 votes

I am new to PHP and was trying to send myself a sample email through PHPmailer. I am using gmail's smtp server. I am trying to send a sample email from my gmail account to my yahoo account. But I am getting the error :

Mailer Error: SMTP connect() failed.

Here is the code :

<?php 


require "class.phpmailer.php"; 
$mail = new PHPMailer(); 
$mail->IsSMTP(); // send via SMTP 
$mail->Host = "ssl://smtp.gmail.com"; 
$mail->SMTPAuth = true; // turn on SMTP authentication 
$mail->Username = "myemail@gmail.com"; // SMTP username 
$mail->Password = "mypassword"; // SMTP password 
$webmaster_email = "myemail@gmail.com"; //Reply to this email ID $email="myyahoomail@yahoo.in"; // Recipients email ID $name="My Name"; // Recipient's name $mail->From = $webmaster_email; $mail->Port = 465; $mail->FromName = "My Name"; $mail->AddAddress($email,$name); $mail->AddReplyTo($webmaster_email,"My Name"); $mail->WordWrap = 50; // set word wrap $mail->IsHTML(true); // send as HTML $mail->Subject = "subject"; $mail->Body = "Hi, This is the HTML BODY "; //HTML Body $mail->AltBody = "This is the body when user views in plain text format"; //Text Body 

if(!$mail->Send()) 
{ 
echo "Mailer Error: " . $mail->ErrorInfo; 
} 
else { echo "Message has been sent"; 
} 
?>

I am using a WAMP server on a Windows 7 64-bit machine so what could be the problem? Please help me solve this. Thanks!

Feb 16, 2022 in Others by Rahul
• 9,680 points
4,477 views

1 answer to this question.

0 votes

 You need to add the Host parameter

$mail->Host = "ssl://smtp.gmail.com";

Also, check if you have open_ssl enabled by using:
 

<?php echo !extension_loaded('openssl')?"Not Available":"Available";

answered Feb 16, 2022 by Aditya
• 7,680 points

Related Questions In Others

0 votes
1 answer

nodetool: Failed to connect to '127.0.0.1:7199' - ConnectException: 'Connection refused (Connection refused)'.

Hi, @Manjima, what do your system logs say? READ MORE

answered Dec 4, 2020 in Others by Rajiv
• 8,910 points
946 views
0 votes
1 answer

Using unserialize in PHP throws the same error repeatedly

I googled 'Node no longer exists', and ...READ MORE

answered Nov 14, 2018 in Others by DataKing99
• 8,250 points
1,509 views
0 votes
1 answer

Where is the documentation to refer for coinbase api integration of Etherium coin currency in php?

Hey there! Please refer to the following ...READ MORE

answered Jan 25, 2019 in Others by Omkar
• 69,230 points
739 views
0 votes
0 answers

PHPMailer: SMTP Error: Could not connect to SMTP host

I am having trouble sending mail through ...READ MORE

May 8, 2022 in PHP by Kichu
• 19,050 points
3,080 views
0 votes
0 answers

Mailer Error: SMTP connect() failed in php mailer( https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting)

Here is code for sending email from ...READ MORE

Jun 2, 2022 in PHP by Kichu
• 19,050 points
12,829 views
0 votes
0 answers

phpmailer error "Could not instantiate mail function"

I'm getting the error "Mailer Error: Could ...READ MORE

Jun 13, 2022 in PHP by narikkadan
• 63,720 points
2,348 views
0 votes
0 answers

How to send email with SMTP in php

I need to send an email using SMTP. ...READ MORE

Jun 24, 2022 in PHP by narikkadan
• 63,720 points
697 views
0 votes
1 answer

PHP & MySQL: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given

Your query seems to have an ERROR ...READ MORE

answered Feb 16, 2022 in Others by Aditya
• 7,680 points
4,694 views
0 votes
1 answer

How do I get the current date and time in PHP?

The time would go by your server ...READ MORE

answered Feb 16, 2022 in Others by Aditya
• 7,680 points
680 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP