我试图建立一个联系表格,我在网上搜索了很多,但没有找到任何有用的解决方案。
这是联系表单HTML和PHP:
<?php
if(isset($_POST['submit']))
{
$message=
'Name: '.$_POST['name'].'<br />
Subject: '.$_POST['message'].'<br />
Email: '.$_POST['email'].'
';
require 'class.phpmailer.php';
require 'PHPMailerAutoload.php';
// Instantiate Class
$mail = new PHPMailer();
// Set up SMTP
$mail->IsSMTP(); // Sets up a SMTP connection
$mail->SMTPAuth = true; // Connection with the SMTP does require authorization
$mail->SMTPSecure = "tls"; // Connect using a TLS connection
$mail->Host = "smtp.gmail.com"; //Gmail SMTP server address
$mail->Port = 587; //Gmail SMTP port
// Authentication
$mail->Username = '**********@gmail.com'; // Your full Gmail address
$mail->Password = '**********'; // Your Gmail password
$mail->SMTPDebug = 1;
// Compose
$mail->SetFrom($_POST['email'], $_POST['name']);
$mail->AddReplyTo($_POST['email'], $_POST['name']);
$mail->Subject = "New Contact Form Enquiry"; // Subject (which isn't required)
$mail->MsgHTML($message);
// Send To
$mail->AddAddress("*********@gmail.com", "Recipient Name"); // Where to send it - Recipient
$result = $mail->Send(); // Send!
$message = $result ? 'Successfully Sent!' : 'Sending Failed!';
unset($mail);
}
?>
<html>
<head>
<title>Contact Form</title>
</head>
<body>
<div style="margin: 100px auto 0;width: 300px;">
<h3>Contact Form</h3>
<form name="form1" id="form1" action="" method="post">
<fieldset>
<input type="text" name="name" placeholder="Full Name" />
<br />
<input type="text" name="message" placeholder="Message" />
<br />
<input type="text" name="email" placeholder="Email" />
<br />
<input type="submit" name="submit" value="Send" />
</fieldset>
</form>
<p><?php if(!empty($message)) echo $message; ?></p>
</div>
</body>
</html>
我得到了这个Error。 我有最新版本的PHPMailer,用户名和密码都是正确的。
有人可以帮忙吗?