2016-07-19 128 views
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="[email protected]"; 
      $mail->Password="[email protected]@!";    
      $mail->SetFrom('[email protected]','xyz '); 
      $mail->FromName="xyz"; 
      $mail->AddAddress($email); 
      $mail->AddReplyTo("[email protected]","xyz "); 
      $mail->Subject = $subject; 
      $mail->Body = "Hello Sir/Madam,"; 
      $mail->IsHTML($message); 
      $mail->Send(); 


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

輸出:「SMTP錯誤:無法驗證」 這是我嘗試的gmail身份驗證。 ID &用於驗證的密碼無疑是完美的。 檢查來自Google的SMTP服務器設置,看起來一樣。 我查了其他帖子,但沒有解決我的問題。 請幫助一樣!提前致謝!SMTP:無法驗證

+0

你基於一個過時的例子代碼,您使用的是舊版本的PHPMailer的,你沒有看過的文檔,或者是什麼的重複這個問題說。 – Synchro

回答

0

你可以試試下面的代碼

 $to = [email protected]; 
     $from = '[email protected]'; 
     $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 = '[email protected]'; 
     $mail->Password = '1234#'; 

     $mail->IsHTML(true); 
     $mail->From="[email protected]"; 
     $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(); 
+0

Dipak感謝您的幫助!你的例子確實是對的!這只是谷歌帳戶的一個小故障。我必須在Google帳戶中啓用「允許安全性較低的應用程序」。 –