Mailer Error SMTP connect failed in php mailer https github com PHPMailer PHPMailer wiki Troubleshooting

0 votes

Here is code for sending email from localhost:

html form:

<form method="post" action="email.php">
  Email: <input name="email" id="email" type="text" /><br />

  Message:<br />
  <textarea name="message" id="message" rows="15" cols="40"></textarea><br />

  <input type="submit" value="Submit" />
</form>

email.php:

<?php

// $email and $message are the data that is being
// posted to this page from our html contact form
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;

require_once('class.phpmailer.php');
require 'PHPMailerAutoload.php';
require 'class.smtp.php';

$mail = new PHPMailer();
$body='hellooooo';
$mail->IsSMTP();

$mail->Host = "ssl://smtp.gmail.com"; // specify main and backup server

$mail->SMTPAuth = true; // turn on SMTP authentication

$mail->Username = "xxxx@gmail.com"; // SMTP username
$mail->Password = "zzz"; // SMTP password
$mailer->SMTPSecure = 'ssl';
$mailer->Port = 465;//587;
$mail->AddAddress("xxx", "xx");
$mail->SetFrom('xxx@gmail.com','xxxx');
$mail->WordWrap = 50;

$mail->IsHTML(true);

$mail->Subject = "You have received feedback from your website!";

$mail->MsgHTML($body);

if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}

echo "Message has been sent";
?>

I am getting this error when I run the code

Message could not be sent.

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

Can someone help me fix this error? 

Jun 2, 2022 in PHP by Kichu
• 19,040 points
13,085 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In PHP

0 votes
0 answers

PHPMailer SMTP ERROR: Failed to connect to server

This Code: <?php include("class.phpmailer.php"); include("class.smtp.php"); $mail = new PHPMailer(); $mail->IsSMTP(); // ...READ MORE

Jun 27, 2022 in PHP by narikkadan
• 63,600 points
1,944 views
0 votes
1 answer

Error:PDOException SQLSTATE[HY000] [2020] No such file or directory in php?

Hello, I checked php -i | grep pdo and noticed ...READ MORE

answered Apr 2, 2020 in PHP by Niroj
• 82,840 points
1,417 views
0 votes
1 answer

Error:“Connection for controluser as defined in your configuration failed” with phpMyAdmin in XAMPP

Hii, I edited /etc/phpmyadmin/config.inc.php and changed the following ...READ MORE

answered Apr 20, 2020 in PHP by Niroj
• 82,840 points
15,300 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,040 points
3,124 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,600 points
2,421 views
0 votes
1 answer

SMTP connect() failed PHPmailer - PHP

 You need to add the Host parameter $mail->Host ...READ MORE

answered Feb 16, 2022 in Others by Aditya
• 7,680 points
4,521 views
0 votes
0 answers

"SMTP Error: Could not authenticate" in PHPMailer

I want to send emails in Gmail ...READ MORE

May 7, 2022 in PHP by narikkadan
• 63,600 points
4,521 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