我正在尝试通过PHPMailer的联系表单发送电子邮件。 我看过教程,因为我之前从未使用过PHPMailer。 这就是我想出来的,但它没有发送电子邮件?
<?php
require_once 'mail/PHPMailerAutoload.php'; // this will include smtp and pop files.
if(isset($_POST['submit'])) {
$email_to = "jacksonhogan01@gmail.com";
// validation expected data exists
if(!isset($_POST['name']) ||!isset($_POST['address']) ||!isset($_POST['subject']) ||!isset($_POST['message'])){
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$address = $_POST['address']; // required
$subject = $_POST['subject']; // required
$message = $_POST['message']; // required
$email_message = "\n\n";
$email_message .= "Name: ".$name."\n";
$email_message .= "Email: ".$address."\n";
$email_message .= "Subject: ".$subject."\n";
$email_message .= "Message: ".$message."\n";
$mail = new PHPMailer();
$mail->isSendmail();
$mail->setFrom($address, $name);
$mail->addAddress($email_to, 'GramsandPops');
$mail->Subject = $subject;
if (!$mail->send()) { //send the message, check for errors
echo "Mailer Error: " . died($error);
} else {
header('Location: contact.php?result=success');
}
}
?>
<div id="contact" class="container">
<div class="contactheader">
<p>Contact</p>
</div>
<form class="form-horizontal"
style="padding-right: 50px; padding-left: 50px; padding-top: 20px;"
action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<label class="control-label col-sm-2">Name:</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="name"
placeholder="Name...">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2">Email:</label>
<div class="col-sm-10">
<input type="email" class="form-control" name="address"
placeholder="Email..">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2">Subject:</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="subject"
placeholder="Subject..">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2">Message:</label>
<div class="col-sm-10">
<textarea class="form-control" cols="40" id="message"
name="message" rows="10" placeholder="Message.."></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-10" style="text-align: center;">
<button style="width: 100px" type="submit" name="submit"
id="submit" class="btn btn-default">Send!</button>
</div>
</div>
</form>
</div>
我有PHPMailerAutoload.php的正确文件路径 我不确定是什么原因引起的。 谢谢你的帮助。