OVH 的 PHPmailer smtp 错误,设置正确并在邮件应用程序中工作

PHPmailer smtp error with OVH, settings correct and work in mail app

我试图让 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 替代品?

简单的错字:

$mail-> UserName=$myemail;

应该是:

$mail->Username=$myemail;

AUTH LOGIN 之后的空命令告诉你 Username 属性 必须为空。

将您的代码基于 PHPMailer 提供的示例总是有帮助的 - 您使用的是非常旧的东西,而且您还使用了旧版本的 PHPMailer,这毫无帮助。