0
<?php
include_once('include/connection.php');

if(isset($_POST['submit']))
{

$name=mysql_real_escape_string($_POST['name']);
$contact=mysql_real_escape_string($_POST['contact']);
$email=mysql_real_escape_string($_POST['email']);
$comments=mysql_real_escape_string($_POST['comments']);

/*
echo var_dump($name);
echo var_dump($contact);
echo var_dump($email);
echo var_dump($comments);
*/

$fdate=date("d/m/Y");



$date = date("m/d/Y h:i:s a");
//echo date("m/d/Y h:i:s a", time());

$query = "INSERT INTO `form_entry`(`name`, `contact`, `email`,  `comments`) 
        VALUES ('$name', '$contact', '$email', '$comments')";
//echo var_dump($query);
mysql_query($query) or die ('Error updating database: '.mysql_error());


//SEND CONFIRMATION EMAIL
        require_once('mailer/class.phpmailer.php');
        $message= "
        <br /><br />
        -------------------------------------------------------------------------------------------------          
        --  Name      :   $name                                            <br>
        --  Contact   :   $contact                                         <br>
        --  Email ID  :   $email                                           <br>
        --  Comments  :   $comments                                        <br>
        ------------------------------------------------------------------------       -------------------------           
                   ";
            $subject = "Enquiry from $name";
            $mail = new PHPMailer();
            $mail->IsSMTP(); 
            //$mail->SMTPDebug  = 0;                     
            $mail->SMTPAuth   = true;                  
            $mail->SMTPSecure = "ssl";                 
            $mail->Host       = "smtp.gmail.com";      
            $mail->Port       = 465;             
            $mail->Username="xyz@gmail.com";  
            $mail->Password="abc123@@!";            
            $mail->SetFrom('xyz@gmail.com','xyz ');
            $mail->FromName="xyz";
            $mail->AddAddress($email);
            $mail->AddReplyTo("xyz@gmail.com","xyz ");
            $mail->Subject = $subject;
            $mail->Body = "Hello Sir/Madam,";
            $mail->IsHTML($message);
            $mail->Send();


echo "<script>alert('Data Saved Successfully');</script>";
mysql_close($connection);
}
?>

Output : " SMTP Error : Could not authenticate " It's gmail authentication I'm trying. ID & Password used to verify are surely perfect. Checked the SMTP server settings from Google, Looks same. I checked with other posts but didn't solve my problem. Pls help for the same! Thanks in advance!

Jainish Kothary
  • 93
  • 1
  • 10
  • You've based your code on an obsolete example, you're using an old version of PHPMailer and you haven't read the docs, or what the duplicates of this question say. – Synchro Jul 19 '16 at 05:33

1 Answers1

0

you can try the below code

        $to = to@gmail.com;
        $from = 'info@test.com';
        $name = 'test.com';
        $mail = new PHPMailer();
        $mail->IsSMTP();
        $mail->SMTPAuth = true; 

        $mail->SMTPSecure = 'ssl';
        $mail->Host = 'bh-24.webhostbox.net';
        $mail->Port = 465;  
        $mail->Username = 'info@test.com';  
        $mail->Password = '1234#';   

        $mail->IsHTML(true);
        $mail->From="info@test.com";
        $mail->FromName="test.com";
        $mail->Sender=$from; // indicates ReturnPath header
        $mail->AddReplyTo($from, $FromName); // indicates ReplyTo headers
        $mail->Subject = $subject;
        $msg  = "this is a test message";
        $mail->Body = $msg;
        $mail->AddAddress($to);
        $mail->Send();
  • Dipak Thanks for your help! Your example is indeed correct ! It was just a glitch from google account. I had to enable "Allow Less Secure Apps" in my google account. – Jainish Kothary Jul 21 '16 at 03:38