简体   繁体   English

OVH的PHPmailer smtp错误,设置正确,可在邮件应用程序中使用

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

I'm trying to get phpmailer to handle contact requests on my website but no matter what I try I get errors. 我正在尝试让phpmailer处理我网站上的联系请求,但是无论我如何尝试都会出现错误。 The following is the code I'm using. 以下是我正在使用的代码。 The SMTP server, login and password all work perfectly in Thunderbird. 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>

In thunderbird the SMTP settings are port 465, connection security SSL/TLS and authentication method is normal password. 在雷鸟中,SMTP设置为端口465,连接安全性SSL / TLS,身份验证方法为常规密码。

The Debug output when I submit the form is: 提交表单时的Debug输出为:

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

I tried enabling and disabling different options for the AUthtype, SMTPAuth etc. but did not get any better results. 我尝试为AUthtype,SMTPAuth等启用和禁用不同的选项,但没有得到任何更好的结果。

Is there something else to change or an alternative to phpmailer that might work better? 是否有其他更改或替代phpmailer的方法可能会更好?

Simple typo: 简单的错字:

$mail-> UserName=$myemail;

Should be: 应该:

$mail->Username=$myemail;

The giveaway there is the empty command after AUTH LOGIN , which tells you that the Username property must be empty. 赠品在AUTH LOGIN之后是一个空命令,该命令告诉您Username属性必须为空。

It always helps to base your code on the examples provided with PHPMailer - you've used something very old, and you're also using an old version of PHPMailer, which never helps. 它始终可以帮助您将代码基于PHPMailer随附的示例-您使用了非常旧的版本,并且还使用了旧版本的PHPMailer,但永远没有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM