Home php教程 php手册 phpmailer发送邮件 SMTP Error: Could not authenticate 错误

phpmailer发送邮件 SMTP Error: Could not authenticate 错误

May 25, 2016 pm 04:49 PM
phpmailer smtp send email

今天在使用phpmailer发送邮件时居然提示SMTP Error: Could not authenticate,这个感觉是smtp设置的问题,下面我在网上找到了几种解决办法。

今天在使用phpmailer发送smtp邮件时提示 SMTP Error: Could not authenticate 错误,其中密码帐号都是正确的,邮箱也设置开启了SMTP功能。

上谷歌百度了一遍,有的说是服务器禁用了端口,有的说把class.phpmailer.php中的,代码如下:

function IsSMTP() {  
	$this->Mailer = 'smtp';  
}//改为  

function IsSMTP() {  
	$this->Mailer = 'SMTP';  
}
Copy after login

测试以后还是不行,心中郁闷的一米,最后在一篇博客中找到了解决方法,先分享出来让更多遇到同样问题的人能得到帮助!

这个错误说明虚拟主机不支持PHPMailer默认调用的fsockopen函数,找到class.smtp.php文件,搜索fsockopen,就找到了这样一段代码:

// connect to the smtp server  
$this->smtp_conn = @fsockopen($host,// the host of the server  
$port,// the port to use  
$errno,   // error number if any  
$errstr,  // error message if any  
$tval);   // give up after ? secs
Copy after login

方法1:将fsockopen函数替换成pfsockopen函数,首先,在php.ini中去掉下面的两个分号

 ;extension=php_sockets.dll

;extension=php_openssl.dll

然后重启一下,因为pfsockopen的参数与fsockopen基本一致,所以只需要将@fsockopen替换成@pfsockopen就可以了。

方法2:使用stream_socket_client函数

一般fsockopen()被禁,pfsockopen也有可能被禁,所以这里介绍另一个函数stream_socket_client(),stream_socket_client的参数与fsockopen有所不同,所以代码要修改为如下:

$this->smtp_conn = stream_socket_client("tcp://".$host.":".$port, $errno,  $errstr,  $tval);

这样就可以了,如果上面办法还是没有解决可能是邮箱自动过滤你机器自动登录邮箱发邮件了哦,我是使用下面办法解决的,刚开始使用的qq的帐号,提示上面错误。换成新注册的163帐号可以正常发送。之后换了一个qq等级比较高的帐号,这下可以正常发送,没有报任何错误。因为收件人用的是qq邮箱帐号,所以发件帐号用qq的邮箱比较好,这样发送过多不会轻易的被拦截或判为垃圾邮件。所以结论就是配置中使用一个qq等级比较高的帐号(我的一个小号等级2个月亮可以正常使用,当然等级越高越好,)

结论:也要查看邮箱中"设置邮件地址黑名单"及"收信规则",有时系统会自动将一些邮箱自动加入黑名单的

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP methods and steps for sending emails to multiple people using PHPMailer PHP methods and steps for sending emails to multiple people using PHPMailer May 22, 2023 pm 06:10 PM

In web applications, it is often necessary to send emails to multiple recipients at once. PHP is a very popular web development language, and PHPMailer is a common PHP class library for sending emails. PHPMailer provides a rich interface, making sending emails in PHP applications more convenient and easy to use. In this article, we will introduce the methods and steps on how to use PHPMailer to send emails to multiple recipients. To download PHPMailer, you first need to go to the official website (

PHP development practice: Use PHPMailer to send emails to users in the MySQL database PHP development practice: Use PHPMailer to send emails to users in the MySQL database Aug 05, 2023 pm 06:21 PM

PHP development practice: Use PHPMailer to send emails to users in the MySQL database Introduction: In the construction of the modern Internet, email is an important communication tool. Whether it is user registration, password reset, or order confirmation in e-commerce, sending emails is an essential function. This article will introduce how to use PHPMailer to send emails and save the email information to the user information table in the MySQL database. 1. Install the PHPMailer library PHPMailer is

How to send HTML mail with embedded images using PHP and PHPMAILER? How to send HTML mail with embedded images using PHP and PHPMAILER? Jul 22, 2023 am 11:29 AM

How to send HTML mail with embedded images using PHP and PHPMAILER? HTML email is a richer and more personalized form of email that can insert pictures, links and styles into the email. Embedded images refer to sending images directly as part of the email in the HTML email instead of sending them as attachments. In PHP, we can use PHPMAILER to send HTML emails with embedded images. PHPMAILER is a powerful PHP email sending library

PHP and PHPMAILER: How to implement anti-spam function for email sending? PHP and PHPMAILER: How to implement anti-spam function for email sending? Jul 22, 2023 am 11:46 AM

PHP and PHPMAILER: How to implement anti-spam function for email sending? Introduction: In the Internet age, email has become an indispensable part of our daily life and work. However, with the popularity and use of email, the problem of spam has become increasingly serious, causing a lot of trouble to users. In order to solve this problem, this article will introduce how to use PHP and PHPMailer library to implement the anti-spam function of email sending. 1. Understand spam. Spam refers to those unsolicited

How to send email using Flask-Mail How to send email using Flask-Mail Aug 02, 2023 am 10:17 AM

How to use Flask-Mail to send emails With the development of the Internet, email has become an important tool for people to communicate. When developing web applications, sometimes we need to send emails in specific scenarios, such as sending a welcome email after a user successfully registers, or sending a password reset email when a user forgets their password, etc. Flask is a simple and flexible Python Web framework, and Flask-Mail is an extension library for sending emails under the Flask framework. This article will introduce how to

How to disable smtp email function in php How to disable smtp email function in php Mar 22, 2023 pm 03:22 PM

PHP is a powerful programming language that is widely used in the field of Web development. The SMTP email function is also an important part of PHP development. However, in some cases, you may want to disable SMTP mail functionality, and this article will explain how to do this.

PHP methods and precautions for sending attachment emails using the PHPMailer library PHP methods and precautions for sending attachment emails using the PHPMailer library May 21, 2023 pm 06:12 PM

PHP methods and precautions for sending attachment emails using the PHPMailer library. Email has become a very important way of communication in modern life. In many development projects, we need to use code to automatically send emails. At this time, the PHPMailer library is our best choice. PHPMailer is a library dedicated to sending emails in PHP. It can easily send emails, including HTML-formatted emails and attachments. This article will focus on how to send emails with attachments in the PHPMailer library.

Mastering PHP and PHPMAILER: How to implement the automatic reply function for email sending? Mastering PHP and PHPMAILER: How to implement the automatic reply function for email sending? Jul 22, 2023 am 11:57 AM

Mastering PHP and PHPMAILER: How to implement the automatic reply function for email sending? In modern society, email has become one of the important ways for people to communicate every day. Many websites or companies need to communicate with users through emails, and automatic reply to emails has become very important. This article will introduce how to use PHP and the PHPMailer library to implement the automatic reply function for email sending. Step 1: Get the user’s email information First, we need to get the user’s email information. On a website or application, use

See all articles