【发布时间】:2018-06-27 17:00:26
【问题描述】:
我正在尝试让 phpmailer 处理我网站上的联系请求,但无论我尝试什么都会出错。以下是我正在使用的代码。 SMTP 服务器、登录名和密码都可以在 Thunderbird 中完美运行。
<html>
<body>
<center>
<br><br><br><br><br><br><br><br>
<p style="font-family:verdana">
Thank you, <?php echo $_POST["fname"]; ?> <?php echo $_POST["lname"]; ?>, for your message!<br>
We will contact you shortly on : <?php echo $_POST["email"]; ?>
</p>
<a href="../../index.html">
<img src="../../assets/images/logo-medium.jpg">
</a>
<?php
//require_once('PHPMailerAutoload.php');
require "vendor/autoload.php";
$errors = '';
$myemail = '****@****.com';
$mypassword = '*******';
if(empty($_POST['fname']) ||
empty($_POST['lname']) ||
empty($_POST['email']) ||
empty($_POST['subject']) ||
empty($_POST['message']))
{
$errors .= "\n Erreur: All fields are required!";
}
$name = $_POST['fname'] . ' ' . $_POST['lname'];
$email_address = $_POST['email'];
$message = 'From : ' . $name . '\n Concerning : ' . $_POST['subject'] . '\n\n' . $_POST['message'] ;
$subject = 'Request from site : ' . $_POST['subject'];
$mail = new PHPMailer();
$mail-> isSMTP();
$mail-> SMTPAuth = true;
$mail-> AuthType = 'LOGIN';
$mail-> SMTPSecure = 'ssl';
$mail-> SMTPHost = 'ssl0.ovh.net';
$mail->Host = 'ssl://ssl0.ovh.net:465';
$mail-> SMTPDebug = 3;
$mail-> Port ='465';
$mail-> isHTML();
$mail-> UserName=$myemail;
$mail-> Password=$mypassword;
$mail-> SetFrom = $myemail;
$mail-> Subject = $subject;
//$mail-> AddAddress($myemail);
$mail-> AddAddress('*****@****.com');
$mail -> Body = $message;
if( empty($errors))
{
$mail -> Send();
}
//else
//print $errors;
?>
</center>
</body>
</html>
在 Thunderbird 中,SMTP 设置为 465 端口,连接安全 SSL/TLS 和身份验证方法为普通密码。
我提交表单时的调试输出是:
2018-06-27 07:59:17 Connection: opening to ssl://ssl0.ovh.net:465, timeout=300, options=array ( )
2018-06-27 07:59:17 Connection: opened
2018-06-27 07:59:17 SERVER -> CLIENT: 220 ssl0.ovh.net player732
2018-06-27 07:59:17 CLIENT -> SERVER: EHLO www.*****.com
2018-06-27 07:59:17 SERVER -> CLIENT: 250-player732.ha.ovh.net 250-SIZE 104857600 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN 250-ENHANCEDSTATUSCODES 250 8BITMIME
2018-06-27 07:59:17 CLIENT -> SERVER: AUTH LOGIN
2018-06-27 07:59:17 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2018-06-27 07:59:17 CLIENT -> SERVER:
2018-06-27 07:59:19 SERVER -> CLIENT: 535 5.7.8 Error: authentication failed: VXNlcm5hbWU6
2018-06-27 07:59:19 SMTP ERROR: Username command failed: 535 5.7.8 Error: authentication failed: VXNlcm5hbWU6
2018-06-27 07:59:19 SMTP Error: Could not authenticate.
2018-06-27 07:59:19 CLIENT -> SERVER: QUIT
2018-06-27 07:59:19 SERVER -> CLIENT: 221 2.0.0 Bye
2018-06-27 07:59:19 Connection: closed
2018-06-27 07:59:19 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
我尝试启用和禁用 AUthtype、SMTPAuth 等的不同选项,但没有得到更好的结果。
还有什么可以改变或替代 phpmailer 可能更好的选择吗?
【问题讨论】: