Please check these things before submitting your issue:
SMTPDebug = 2 setAre you trying to send mail via SMTP using a username/password? If so, what service provider and port number are you using? The wiki at https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting provides some basic recommendations to check.
i solve it by adding this line of code:
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
im using ssl 465..
and its really important to do this on your gmail account.
basically turned it on.
"Access for less secure apps has been turned on"
Read the docs. That is not a real solution; it just hides the problem and makes your app vulnerable to man-in-the-middle attacks. You do not need to enable access for less secure apps if you use XOAUTH2 authentication, which PHPMailer supports. This is also documented and included in examples.
Assalamualaikkum...
Hi @vladstarrk , i'm very thanks for your solution. That solve my problem.. Thanks.
Read the docs. What your'e doing is unsafe. Your code is now simply hiding the error and you are vulnerable to man in the middle attacks. Gmail does not publish invalid or expired certificates - it's a configuration problem on your server, so fix your server instead of pretending to.
SMTP connect() failed ..please help me..
this is my code..
$mail->SMTPDebug = $debug; // Debug Mode
// Step 2 (Optional) - If you don't receive the email, try to configure the parameters below:
$mail->IsSMTP(); // Set mailer to use SMTP
//$mail->Host = 'mail.yourserver.com';
$mail->Host = 'http://localhost/properties/contact.php'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->Port = 587; // TCP port to connect to
$mail->AddAddress($email); // Add another recipient
//$mail->AddAddress('[email protected]', 'Person 2'); // Add a secondary recipient
//$mail->AddCC('[email protected]', 'Person 3'); // Add a "Cc" address.
//$mail->AddBCC('[email protected]', 'Person 4'); // Add a "Bcc" address.
$mail->SetFrom($email, $_POST['name']);
$mail->AddReplyTo($_POST['email'], $_POST['name']);
$mail->IsHTML(true); // Set email format to HTML
$mail->CharSet = 'UTF-8';
$mail->Subject = $subject;
$mail->Body = $message;
$mail->Send();
$arrResult = array ('response'=>'success');
Don't post unrelated comments on closed issues, especially since you can apparently find the time to post multiple comments, but not to read any documentation. It's rude.
The Host property needs a host name, not a URL - in your case use localhost. Using localhost will not work with TLS, and you probably don't need authentication, so do this:
$mail->SMTPAuth = false;
$mail->SMTPSecure = false;
Also you're doing no error checking at all, so if anything fails you won't know why - base your code on the up to date examples provided with PHPMailer, and not the obsolete one you have used.
SMTP connect() failed ..please help me..
this is my code..
note : localt host
if($_SERVER['REQUEST_METHOD'] =='POST')
{
require'mailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, ssl also accepted
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->Port = 465; // TCP port to connect to
$mail->isHTML(); // Set email format to HTML
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'added'; // SMTP password
$mail->setFrom($_POST['email'],$_POST['name'] );
$mail->addAddress('[email protected]', 'مدرسة الثروات الوطنيه الخاصه');
$mail->addAddress(''); // Name is optional
$mail->addReplyTo($_POST['email'], 'Information');
//$mail->addCC('[email protected]');
//$mail->addBCC('[email protected]');
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->Subject = $_POST['subject'];
$mail->Body = $_POST['body'];
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo ' تم ارسال الرساله بنجاØ';
}
}
Please read the troubleshooting guide. You'll also want to change your password now you've posted it in public.
I keep getting this error after setting up the PHP mailer. I followed the instructions but I am still getting this error:

Most helpful comment
i solve it by adding this line of code:
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
im using ssl 465..
and its really important to do this on your gmail account.
basically turned it on.
"Access for less secure apps has been turned on"