Summary of Phpmailer mass gmail FAQ _php Tips

Source: Internet
Author: User
Tags openssl gmail password

Everyone in Phpmailer mass Gmail will encounter many common problems, the following for you to sum up some common problems, I hope to help you learn.

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

# extract

tar ZXVF php-5.2.14.tar.gz

# Enter PHP OpenSSL expansion module Directory

CD php-5.2.14/ext/openssl/

/var/www/php5/bin/phpize # Here for your own phpize path, if you cannot find it, use Whereis phpize to find the

# execution, find the error cannot 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= When the/var/www/php5/bin/php-config

make makes install # installation completes, 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 extension=openssl.so at the end of file to 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.

To share a phpmailer to send a Gmail email instance:

 

The above is the entire content of this article, I hope to help you learn.

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.