我有一个我正在处理的Bootstrap网站的contact_me.php表单,我必须添加PHPMailer才能对联系我们表单进行SMTP身份验证。我不确定在contact_me.php中我在哪里添加PHPMailer php进行SMTP身份验证。现在,联系表格工作我只是没有收到发送的电子邮件。谢谢!
contact_me.php
<?php
// check if fields passed are empty
if(empty($_POST['name']) ||
empty($_POST['phone']) ||
empty($_POST['email']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$phone = $_POST['phone'];
$email_address = $_POST['email'];
$message = $_POST['message'];
// create email body and send it
$to = 'person@website.com'; // PUT YOUR EMAIL ADDRESS HERE
$email_subject = "Website Contact Form: $name"; // EDIT THE EMAIL SUBJECT LINE HERE
$email_body = "You have received a new message from your website's contact form.\n\n"."Here are the details:\n\nName: $name\n\nPhone: $phone\n\nEmail: $email_address\n\nMessage:\n$message";
$headers = "From: noreply@website.com\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
和PHPMailer代码:
require_once('path/to/library/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "smtp.postmarkapp.com";
$mail->Port = 26;
$mail->Username = "#@#@#@#@-####-@@@@-#####-@#@#@#@#@#@#";
$mail->Password = "#@#@#@#@-####-@@@@-#####-@#@#@#@#@#@#";
$mail->SetFrom('name@yourdomain.com', 'Web App');
$mail->Subject = "A Transactional Email From Web App";
$mail->MsgHTML($body);
$mail->AddAddress($address, $name);
if($mail->Send()) {
echo "Message sent!";
} else {
echo "Mailer Error: " . $mail->ErrorInfo;
}
答案 0 :(得分:0)
解决方案:我最终在GitHub上使用IceTimux的PHPMailer SMTP Bootstrap Contact Form解决方案。你可以在这里抓住它: https://github.com/IceTimux/SMTP-Bootstrap-Contact-Form