【问题标题】:PHPmailer smtp error with OVH, settings correct and work in mail appOVH的PHPmailer smtp错误,设置正确并在邮件应用程序中工作
【发布时间】: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 可能更好的选择吗?

【问题讨论】:

    标签: php phpmailer


    【解决方案1】:

    简单的错字:

    $mail-> UserName=$myemail;
    

    应该是:

    $mail->Username=$myemail;
    

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

    将您的代码基于 PHPMailer 提供的示例总是有帮助的 - 您使用了一些非常旧的东西,并且您还使用了旧版本的 PHPMailer,这从来没有帮助。

    【讨论】:

    • 酷,谢谢!完全披露:我发现 似乎 可以工作的唯一教程需要旧版本的 PHPMailer,我从中复制了代码,但最终还是把它搞砸了。
    • 这是维护 PHPMailer 的麻烦之一 - 它已经存在了很长时间(自 2001 年以来),以至于有很多东西已经过时了很多年 - 总是go to the source。跨度>
    猜你喜欢
    • 2017-08-28
    • 1970-01-01
    • 2017-01-19
    • 1970-01-01
    • 2015-11-23
    • 2021-01-24
    • 2012-11-28
    • 2011-09-06
    • 1970-01-01
    相关资源
    最近更新 更多