<?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);
}
?>
输出:“SMTP错误:无法验证” 这是我正在尝试的gmail身份验证。 ID&amp;用于验证的密码肯定是完美的。 检查了Google的SMTP服务器设置,看起来一样。 我检查了其他帖子,但没有解决我的问题。 请帮忙!提前谢谢!
答案 0 :(得分:0)
您可以尝试以下代码
$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();