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
205 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
251 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
779 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,190 points
255 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,190 points
5,699 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
• 16,050 points
21 views
+1 vote
2 answers

Scp Php files into server using gradle

Tru something like this: plugins { id ...READ MORE

answered Oct 11, 2018 in DevOps & Agile by lina
• 8,220 points
507 views
0 votes
1 answer

How do I create folder under an Amazon S3 bucket through PHP API?

Of Course, it is possible to create ...READ MORE

answered Apr 24, 2018 in AWS by anonymous
8,991 views
0 votes
1 answer

Failure uploading Image on AmazonS3 with PHP SDK

Try this, I took it out from ...READ MORE

answered May 4, 2018 in AWS by Cloud gunner
• 4,650 points
2,022 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
16 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