About the Phpmailer mass gmail problem

Source: Internet
Author: User
Tags config ini mail connect openssl

I will only some basic phpmailer usage, such a message of mass function also puzzled me a week, the following I encountered problems for everyone to sum up

1.Could not authenticate

First of all, if you do not use the loop, it is basically the account or password is wrong;

If you use the loop to Mass, send () method after the end remember to call Smtpclose (), send a shutdown once, otherwise there will be only send an e-mail, the second crash situation.

2.Gmail

First, open the SSL permissions for PHP

PHP to open the OpenSSL method, most of the OpenSSL is not open, to enable the need for a simple setting:

windows open Method:

1: First check php.ini, extension=php_openssl.dll whether exist, if present remove the previous annotation character '; ', if it does not exist, then add Extension=php_openssl.dll.

2: Speak php folder under: Php_openssl.dll, Ssleay32.dll, Libeay32.dll 3 files copied to windows\system32\ folder.

3: Restart Apache or IIS

At this point, the OpenSSL function is turned on.

Linux to open the method:

I am using Kam still data Cloud host, PHP version: 5.2.14

The following scenario takes my host as an example to add OpenSSL module support for PHP.

Some answers on the internet say you want to recompile PHP, add configure parameters, and increase OpenSSL support. Here is a method that requires no recompilation.

If there is a PHP installation package file on the server best, if deleted, go to download and Phpinfo page display version of the same PHP installation file, I am here php-5.2.14.tar.gz

recommended to Sohu Mirror download, NetEase Mirror did not find. The address is: http://mirrors.sohu.com/php/

Connect to the host with the SSH tool.

# Download to/var/www/php5 directory

Cd/var/www/php5

wget http://mirrors.sohu.com/php/php-5.2.14.tar.gz

# decompression

Tar zxvf php-5.2.14.tar.gz

# Enter PHP's OpenSSL extension Module directory

CD php-5.2.14/ext/openssl/

/var/www/php5/bin/phpize # Here for your own phpize path, if not found, use Whereis phpize to find

# After the execution, found that the error can not find Config.m4, CONFIG0.M4 is config.m4. Direct rename

MV Config0.m4 CONFIG.M4

/var/www/php5/bin/phpize

./configure--with-openssl--with-php-config=/var/www/php5/bin/php-config

Make

Make install

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/PHP/

# After the installation is complete, a directory of. so files (openssl.so) is returned. Under this directory, copy the openssl.so file to the extension_dir you specified in php.ini (Find in php.ini file: Extension_dir =), my directory here is var/www/php5/lib/php/ Extensions

# edit php.ini file, add at end of file

Extension=openssl.so

# Restart Apache

/usr/local/apache2/bin/apachectl restart

OK, now you can successfully add OpenSSL support.

But Gmail's trouble is more than that, and Gmail's SMTP and POP3 are now SSL-encrypted.

Step1. PHP OpenSSL module (extension) support STEP2. Download Phpmailer Library STEP3. Change code ' class.phpmailer.php ' and ' class.smtp.php ' 1.phpmailer and SMTP Riga property Is_ssl

Public$is_ssl = false;

The Smtpconnect method in 2.phpmailer is passed to the SMTP object

$this->smtp-> Is_ssl  = $this-> is_ssl;

The Connect method in 3.SMTP is preceded by the Fsockopen call

if ($this->is_ssl) {$host = ' ssl://'. $host;}

Finally, the use of methods, remember to call the Phpmailer class Oh, the code does not.

$mail = new Phpmailer ();
$mail->issmtp ();
$mail->host = ' smtp.gmail.com '; Your corporate Post office domain name
$mail->smtpauth = true;//Turn on SMTP authentication
$mail->smtpsecure = "TLS";
$mail->username = ' * * * @gmail. com ';
$mail->password = ' Hu Jintao ';
$mail->from = ' * * *;
$mail->fromname = ' * * *;
$mail->charset = ' UTF-8 ';
$mail->encoding = "base64";
$mail->ishtml (TRUE); Send As HTML
$mail->subject = "* * *";//Mail title
$mail->body = ' * * */mail content
$mail->altbody = "text /html ";
$mail->addaddress (' * * *, "");
$mail->is_ssl = true;
$mail->port = 587;
if (! $mail->send ()) {
       exit ($mail->errorinfo);
}
$mail->smtpclose ();
Unset ($mail);

The Code section on these, and don't forget to do the corresponding settings in Gmail Oh.

With the above three steps, you are free to use Phpmailer to send Gmail messages.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.