我正在关注如何构建联系表单的phpacademy教程。一切都很好,但最后它显示了一个致命的错误未定义的方法phpmailer :: issmpt()在第27行
<?php
session_start();
require_once 'phpmailer/PHPMailerAutoload.php';
$errors = [];
if(isset($_POST['name'], $_POST['email'], $_POST['message'])){
$fields = [
'name' => $_POST['name'],
'email' => $_POST['email'],
'message' => $_POST['message']
];
foreach($fields as $field =>$data){
if(empty($data)) {
$errors[]= 'The' . $field . ' field is required. ';
}
}
if(empty($errors)){
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = 'smtp.gmail.com';
$mail->Username = 'email@gmail.com';
$mail->Password = 'pass';
$mail->SMPTSecure = 'ssl';
$mail->Port = 465;
$mail->isHTML();
$mail->Subject = 'Contact from submitted';
$mail->Body = 'From: ' . $fields['name'] . ' (' .$fields['email'] .') <p>' . $fields['message'] . '</p>';
$mail->FromName = 'Contact';
$mail->AddAddress('email@gmail.com', 'name');
if($mail->send()){
header('Location: thanks.php');
die();
}else{
$errors[] = 'Sorry, could not send email. Try again later.';
}
}
}else{
$errors[] = 'Something went wrong.';
}
$_SESSION['errors']= $errors;
$_SESSION['fields']= $fields;
header('Location:index.php');
?>