Summarize the common problems of PHPmailer group-sending Gmail, and phpmailer group-sending gmail

Source: Internet
Author: User
Tags gmail mail gmail password

Summarize the common problems of PHPmailer group-sending Gmail, and phpmailer group-sending gmail

You may encounter many Frequently Asked Questions in PHPmailer Group Sending Gmail. The following summarizes some frequently asked questions and hopes to help you learn them.

1. cocould not authenticate

First, if you do not use the loop, the account or password is incorrect;

If you use a loop to send a group, remember to call Smtpclose () after the send () method is complete and send it once. Otherwise, only one email is sent and the second message crashes.

2. Gmail

First, enable the ssl permission for php

Openssl is disabled in php in most cases. To enable openssl, perform the following simple settings:

How to enable it in windows:

1: first check whether the extension = php_openssl.dll exists in php. ini. If yes, remove the comment ';'. If no such line exists, add extension = php_openssl.dll.

2. Copy the php_openssl.dll, ssleay32.dll, and libeay32.dll files in the php folder to the WINDOWS \ system32 \ folder.

3: restart apache or iis

Now, openssl is enabled.

In Linux:

I am using the cloud host of jinshang data. PHP version: 5.2.14

The following solution uses my host as an example to explain how to add openssl module support for PHP.

Some answers on the Internet are to re-compile PHP, add the configure parameter, and add openssl support. Here is a method that does not need to be re-compiled.

If there is a PHP installation package file on the server, it is best to, if it has been deleted, go to download and phpinfo page shows the version of the same PHP installation file, I here is the php-5.2.14.tar.gz

We recommend that you download the image from Sohu. The Netease image is not found. Address:Http://mirrors.sohu.com/php/

Connect to the host using ssh tools.

# Download to/var/www/php5 directory cd/var/www/php5wget http://mirrors.sohu.com/php/php-5.2.14.tar.gz# unzip tar zxvf php-5.2.14.tar.gz # Enter PHP openssl extension Module Directory cd php-5.2.14/ext/openssl // var /www/php5/bin/phpize # Here is your phpize path, if not found, use whereis phpize to find # after execution, the config cannot be found if an error is found. m4, config0.m4 is config. m4. Rename the mv config0.m4 config directly. m4/var/www/php5/bin/phpize. /configure -- with-openssl -- with-php-config =/var/www/php5/bin/php-configmakemake install # After the installation is complete, a message is returned. so file (openssl. so) directory. Openssl. so file copy to you in php. under extension_dir specified in ini (in php. search for extension_dir = In the INI file. The directory here is var/www/php5/lib/php/extensions # edit php. INI file, add extension = openssl at the end of the file. so # restart Apache to/usr/local/apache2/bin/apachectl restart

Now, openssl support is successfully added.

However, there are more and more problems with Gmail. smtp and pop3 In Gmail are both ssl-encrypted.

Step1. php openssl module (extension) support
Step2. download phpmailer library
Step3. change code 'class. phpmailer. php' and 'class. smtp. php'

1. Add property Is_SSL to phpmailer and smtp

public $Is_SSL = false;

2. The SmtpConnect method in phpmailer is passed to the smtp object.

$this->smtp-> Is_SSL = $this-> Is_SSL ;

3. Before calling fsockopen, add the Connect Method in smtp

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

Finally, the method is used. Remember to call the phpmailer class. The Code does not exist.

$ Mail = new PHPMailer (); $ mail-> IsSMTP (); $ mail-> Host = 'smtp .gmail.com '; // your enterprise Post Office domain name $ mail-> SMTPAuth = true; // turn on SMTP authentication $ mail-> SMTPSecure = "tls "; $ mail-> Username = '*** @ gmail.com'; $ mail-> Password = '******'; $ mail-> From = '***'; $ mail-> FromName = '***'; $ mail-> CharSet = 'utf-8 '; $ mail-> Encoding = "base64"; $ mail-> IsHTML (true); // send as HTML $ mail-> Subject = '***'; // mail title $ mail-> Body =' * ** '; // Email content $ mail-> AltBody = "text/html"; $ mail-> AddAddress ('***',""); $ mail-> Is_SSL = true; $ mail-> Port = 587; if (! $ Mail-> Send () {exit ($ mail-> ErrorInfo);} $ mail-> Smtpclose (); unset ($ mail );

Do not forget to set the code in gmail.

After completing the preceding three steps, you can use phpmailer to send gmail emails.

I will share with you an example of sending a gmail email to phpmailer:

The above is all the content of this article, hoping to help you learn.

Articles you may be interested in:
  • PHP obtains the Email Contact addresses such as 163, gmail, and 126 (9.10.10 tested]
  • Php simulated GMAIL, HOTMAIL (MSN), YAHOO, 163,126 email logon details
  • PHP source code for mass mailing
  • Phpmailer details on sending gmail mail instances
  • Java, php, C #, asp
  • Php allows unlimited mass mailing of public accounts
  • PHP + swoole implement simple multi-person online chat group
  • PHP mass mailing machine implementation code

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.