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 in Others by Rahul
• 8,980 points
624 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 by Aditya
• 7,280 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
296 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,240 points
805 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,210 points
267 views
0 votes
1 answer

Execute a shell script with php

One of the possible reason for this ...READ MORE

answered Feb 24, 2019 in Others by Omkar
• 69,210 points
5,820 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 in PHP by Kichu
• 19,040 points
134 views
0 votes
0 answers
0 votes
0 answers

phpmailer error "Could not instantiate mail function"

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

Jun 13 in PHP by narikkadan
• 10,840 points
24 views
0 votes
0 answers

How to send email with SMTP in php

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

6 days ago in PHP by narikkadan
• 10,840 points
9 views
0 votes
1 answer
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 in Others by Aditya
• 7,280 points
26 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP