我正在尝试使用phpmailer发送带有HTML表单的电子邮件。我目前在我的项目中有最新版本,但是出现了一个错误。
代码:
<?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('sebastian.vireal@gmail.com', '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;
}
我尝试过从require更改为include。我也尝试过包含PHPMailerAutoload.php文件。
非常感谢帮助。
答案 0 :(得分:1)
请检查功能拼写。如果它不起作用 然后使用
$valid = phpMailer::ValidateAddress($email_address);