2

I am unable to send mail through Gmail smtp settings... On the other hand without any authentiacation i am getting mail from sg2nlhg096.shr.prod.sin2.secureserver.net server name.

SMTP settings code.

require_once "class.phpmailer.php";
require_once('class.smtp.php');

$mail = new PHPMailer(true);
$mail->IsSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'abc@gmail.com';
$mail->Password = '*************';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;

$mail->setFrom('johndoe@gmail.com', 'John');
$mail->addReplyTo('replyto@example.com', 'Doe');
$mail->addAddress('mr.shah118@gmail.com', 'John Doe');

$mail->Subject = 'PHPMailer GMail SMTP test';

$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));

$mail->AltBody = 'This is a plain-text message body';

if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
echo 0;
} else {
echo "Message sent!";
echo 1;
}

Simple Mail settings ...

require("class.phpmailer.php");
$mail = new PHPMailer();  // create a new object
$mail->From = $_POST['email1'];
$mail->FromName = $_POST['name1'];


$mail->addAddress("techdynastic@gmail.com", "Dynastictech Form");

//Address to which recipient will reply
$mail->addReplyTo($_POST['email1'], "Reply");
$mail->isHTML(true);

$mail->Subject = 'hidden_subject';
$mail->Body = 'body';
$mail->AltBody = "Thanks";


if (!$mail->Send()) {
//echo 'error'. mysqli_error($con);
echo 0;
} else {
//echo 'Message has beeen successfully send. we will contact as soon!';
echo 1;
}

My Html file with ajax call

$.ajax({
                        type: "POST",
                        url: "../send_form_email.php",
                        data: dataString,
                        cache: false,
                        success: function (data) {
                            //$(".success_mes").html(data);

                            if (data == 1)
                            {
                                $(".success_mes").html("Message has beeen successfully send.");
                                $('#name').val('');
                                $("#email").val('');
                                $("#phone").val('');
                                $("#subject").val('');
                                $("#comments").val('');
                            } else
                            {
                                $(".mail_error").html("*Something Went Wrong ..");
                            }
                        },
                    });
TMA
  • 1,419
  • 2
  • 22
  • 49

1 Answers1

0

You can enable Debug to see more details:

$mail->SMTPDebug  = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only