I am completely new to PHP and I want to send a mail using PHP. I have a Contact Us form whcih will accept email is of the person contacting me and therefore the mail will be sent to me. I am using PHPMailer library from https://github.com/PHPMailer/PHPMailer/tree/master and following is the code snippet 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 am getting the error " Message was not sent.Mailer error: SMTP connect() failed." I am not getting what is the problem..? $mail->Host = ""; please comment on what this stands for??
Add
$mail->SMTPDebug = 1;
and try to debug the problem.As very well exampled by @joydesigner, To connect via SMTP, you will need to pass
hostname, username and password
and then it should connect and send email.Here I see you have passed only,
host
information, pls addusername & password
as well and try once.Also check that
TLS/SSL PORT
is open for your server:check with:
Maybe it is your configuration problem.
example of phpmailer configuration is like this:
Here the $mail->Host is the smtp mail server. Normally started with smtp.
You should check the tcp port 25 of the resolver1.opendns.com , it seens being block or not starting up the stmpd such as sendmail or some MTA.
try telnet resolver1.opendns.com 25
and you will find tcp port 25 is not opened.