PHPmailer group-sending Gmail FAQ _ PHP Tutorial

Source: Internet
Author: User
PHPmailer group Gmail FAQ. 1. couldnotauthenticate first, if you do not use a loop, it is basically an incorrect account or password. if you use a loop to send a group, remember to call Sm 1 after the send () method ends. 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 the/var/www/php5 Directory

Cd/var/www/php5

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

# Decompress

Tar zxvf php-5.2.14.tar.gz

# Enter the PHP openssl extension module directory

Cd php-5.2.14/ext/openssl/

/Var/www/php5/bin/phpize # Here is your own phpize path. if you cannot find it, use whereis phpize to find it.

# If an error is found after execution, config. m4 cannot be found. config0.m4 is config. m4. Rename directly

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

# After the installation is complete, a directory of the. so File (openssl. so) will be returned. Openssl. so file copy to you in php. under extension_dir specified in ini (in php. in the INI file, find: extension_dir =). The Directory here is var/www/php5/lib/php/extensions.

# Edit the php. ini file and add it at the end of the file

Extension = openssl. so

# Restart Apache.

/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 = '***'; // 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 );

Do not forget to set the code in gmail.

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

Http://www.bkjia.com/PHPjc/765063.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/765063.htmlTechArticle1.Could not authenticate first, if you do not use a loop, it is basically the account or password is wrong; if you use a loop to group, after the send () method ends, remember to call Sm...

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.