我最近一直在使用phpmailer作为联系表单,但是当我尝试将联系表单发送到电子邮件时,会导致错误。任何帮助将不胜感激!请记住,这是使用xampp localhost。另外我的contact.php重定向到另一个页面,我的错误是
2016-02-21 00:02:19无效地址:(addAnAddress Reply-To):11 注意:未定义的属性:PHPMailer :: $ in C:\ xampp \ htdocs \ Guild 第51行的网站\ contact.php
Contact.php脚本也是 -
<?php
ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
session_start();
require_once 'libs/phpmailer/PHPMailerAutoload.php';
$errors = [];
if(isset($_POST['name'], $_POST['email'], $_POST['ign'], $_POST['gamepref'], $_POST['cps'], $_POST['anythingelse'])) {
$fields = [
'name' => $_POST['name'],
'e-mail' => $_POST['email'],
'IGN' => $_POST['ign'],
'game preference' => $_POST['gamepref'],
'CPS' => $_POST['cps'],
'anything else' => $_POST['anythingelse'],
];
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->SMTPDebug = 2;
$mail->Host = 'smtp.gmail.com';
$mail->Username = 'somemail@gmail.com';
$mail->Password = 'pass';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->isHTML();
$mail->Subject = '$fields[\'name\'] is wanting to apply.';
$mail->Body = '<p>Name: $fields[\'name\']</p><p>E-Mail: $fields[\'e-mail\']</p><p>IGN: $fields[\'IGN\']</p><p>Game Preference: $fields[\'game preference\']</p><p>CPS: $fields[\'CPS\']</p><p>Message: $fields[\'anything else\']</p>';
$mail->FromName = 'Contact';
$mail->AddReplyTo($fields['e-mail'], $fields['name']);
$mail->AddAddress('somemail@gmail.com');
if($mail->send) {
header('Location: thanks.php');
die();
} else {
$errors[] = 'Sorry, could not send email. Try again later.';
}
}
} else {
$errors[] = "Something went wrong! (Mabye it is because you didn't put anything!)";
}
$_SESSION['errors'] = $errors;
$_SESSION['fields'] = $fields;
答案 0 :(得分:0)
刚刚找到解决方案!首先我切换到tls,然后我添加了 - $ mail-&gt; SMTPOptions = array( &#39; SSL&#39; =&GT;阵列( &#39; verify_peer&#39; =&GT;假, &#39; verify_peer_name&#39; =&GT;假, &#39; allow_self_signed&#39; =&GT;真正 ) 最后允许不太安全的gmail应用程序。