0
我有一個contact_me.php表單,用於我正在處理的引導程序網站,並且我必須添加PHPMailer才能爲Contact Us表單進行SMTP身份驗證。我不確定在contact_me.php中爲SMTP驗證添加了PHPMailer php。現在,聯繫表單正在工作,我只是沒有收到發送的電子郵件。謝謝!將SMTP添加到引導程序contact_me.php
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 = '[email protected]'; // 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: [email protected]\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 = "#@#@#@#@-####[email protected]@@@-#####[email protected]#@#@#@#@#@#";
$mail->Password = "#@#@#@#@-####[email protected]@@@-#####[email protected]#@#@#@#@#@#";
$mail->SetFrom('[email protected]', '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;
}
你在PHPMailer代碼中發送了誰? –
它與contact_me.php中的「$ to ='[email protected]'」是同一個人 – Andrea
我看不到$ address是在哪裏初始化的,這就是爲什麼我要求 –