我想用phpmailer發送帶有HTML表單的電子郵件。我目前在我的項目中有最新版本,但出現錯誤。Phpmailer未定義的方法錯誤
代碼:
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = trim(filter_input(INPUT_POST, "name", FILTER_SANITIZE_STRING));
$email = trim(filter_input(INPUT_POST, "email", FILTER_SANITIZE_EMAIL));
$adress = trim(filter_input(INPUT_POST, "adress", FILTER_SANITIZE_STRING));
$date = trim(filter_input(INPUT_POST, "date", FILTER_SANITIZE_STRING));
$timefrom = trim(filter_input(INPUT_POST, "timefrom", FILTER_SANITIZE_STRING));
$timeto = trim(filter_input(INPUT_POST, "timeto", FILTER_SANITIZE_STRING));
$payment = trim(filter_input(INPUT_POST, "payment", FILTER_SANITIZE_STRING));
if ($name === "" || $email === "" || $adress === "" || $date === "" || $timefrom === "" || $timeto === "" || $payment === "") {
echo "Please fill in all fields";
exit;
}
require('phpmailer/class.phpmailer.php');
$mail = new PHPMailer;
if (!$mail->ValidateAdress($email)) {
echo "Invalid Email Adress";
exit;
}
$email_body = "";
$email_body .= "Name: " . $name . "\n";
$email_body .= "Email: " . $email . "\n";
$email_body .= "Adress: " . $adress . "\n";
$email_body .= "Date: " . $date . "\n";
$email_body .= "Time from: " . $timefrom . "\n";
$email_body .= "Time to: " . $timeto . "\n";
$email_body .= "Payment Method: " . $payment . "\n";
// PHP MAILER CODE:
$mail->setFrom($email, $name);
$mail->addAddress('[email protected]', 'Soreal main account'); // Add a recipient
$mail->isHTML(false); // Set email format to HTML
$mail->Subject = 'Soreal VR Contact Form' . $name;
$mail->Body = $email_body;
if (!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
header("location:thankyou.php");
}
?>
錯誤:
Fatal error: Call to undefined method PHPMailer::ValidateAdress() in /home/soreal/public_html/process.php on line 23
錯誤發生下面的IF語句的行:
$mail = new PHPMailer;
if (!$mail->ValidateAdress($email)) {
echo "Invalid Email Adress";
exit;
}
我已經嘗試將需求改爲包含。我也嘗試過包括PHPMailerAutoload.php文件。
幫助將不勝感激。
'validateAddress'檢查拼寫 – dinesh
錯字的問題是題外話。 –