SMTP connect () error in PHPMailer

I am completely new to PHP and I want to send mail using PHP. I have a Contact Us form that will receive an email from the person who contacted me, and therefore an email will be sent to me. I am using the PHPMailer library from https://github.com/PHPMailer/PHPMailer/tree/master and the following is the code snippet that I am using.

<?php require("class.phpmailer.php"); $mail = new PHPMailer(); $mail->IsSMTP(); $mail->SMTPSecure = 'tls'; $mail->Host = "resolver1.opendns.com"; // this SMTP server of my machine //$mail->Host = "208.67.222.222";//ip ; which one to use the resolver1.opendns.com or 208.67.222.222 ??? $mail->From = " xyz@gamil.com ;//email id of the person $mail->AddAddress(" datta.dhonde@coreathena.com ");//my email id $mail->Subject = "First PHPMailer Message"; $mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer."; $mail->WordWrap = 50; if(!$mail->Send()) { echo 'Message was not sent.'; echo 'Mailer error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent.'; } ?> 

I get the error message "Message not sent. Sender error: SMTP connect () error". I do not understand what the problem is.? $ mail-> Host = ""; comment what does this mean?

+6
source share
4 answers

Add $mail->SMTPDebug = 1; and try to debug the problem.

+23
source

As @joydesigner can clearly see, to connect via SMTP you need to go through hostname, username and password , and then it must connect and send an email.

 $mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup server $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'jswan'; // SMTP username $mail->Password = 'secret'; // SMTP password $mail->SMTPSecure = 'tls'; // tls or ssl connection as req 

Here I see that you just passed the host information, add another username & password and try once.

Also check that TLS/SSL PORT open for your server:

check:

 telnet resolver1.opendns.com 25 
+4
source

Perhaps this is your configuration problem.

An example phpmailer configuration is as follows:

 <?php require 'class.phpmailer.php'; $mail = new PHPMailer; $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup server $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'jswan'; // SMTP username $mail->Password = 'secret'; // SMTP password $mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted $mail->From = ' from@example.com '; $mail->FromName = 'Mailer'; $mail->addAddress(' josh@example.net ', 'Josh Adams'); // Add a recipient $mail->addAddress(' ellen@example.com '); // Name is optional $mail->addReplyTo(' info@example.com ', 'Information'); $mail->addCC(' cc@example.com '); $mail->addBCC(' bcc@example.com '); $mail->WordWrap = 50; // Set word wrap to 50 characters $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name $mail->isHTML(true); // Set email format to HTML $mail->Subject = 'Here is the subject'; $mail->Body = 'This is the HTML message body <b>in bold!</b>'; $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; exit; } echo 'Message has been sent'; 

Here $ mail-> Host is the smtp mail server. It usually starts with smtp.

+1
source

You should check the tcp 25 port on resolver1.opendns.com, it will block or not start stmpd, for example sendmail or some MTA.

try telnet resolver1.opendns.com 25

and you will find that tcp 25 port does not open.

0
source

Source: https://habr.com/ru/post/955644/


All Articles