Home > Backend Development > PHP Tutorial > Frequently Asked Questions about PHPmailer Mass Sending to Gmail_PHP Tutorial

Frequently Asked Questions about PHPmailer Mass Sending to Gmail_PHP Tutorial

WBOY
Release: 2016-07-13 10:30:35
Original
974 people have browsed it

1.Could not authenticate

First of all, if you don’t use loops, it’s basically because your account or password is wrong;
If you use a loop to send mass messages, remember to call Smtpclose() after the send() method is completed, and send and close once. Otherwise, you will only be able to send one email and it will crash the second time.
2.Gmail
First, enable php’s ssl permissions
How to enable openssl in php. In most cases, openssl is not enabled. To enable it, you need to make the following simple settings:
How to open it under windows:
1: First check whether extension=php_openssl.dll exists in php.ini. If it exists, remove the previous comment character ‘;’. If this line does not exist, add extension=php_openssl.dll.
2: Copy the three files in the php folder: php_openssl.dll, ssleay32.dll, libeay32.dll to the WINDOWSsystem32 folder.
3: Restart apache or iis
At this point, the openssl function is enabled.
How to enable it under Linux:
I am using the cloud host of Jinshang Data, PHP version: 5.2.14
The following plan uses my host as an example to explain adding openssl module support to PHP.
Some answers on the Internet say that you need to recompile PHP, add configure parameters, and add openssl support. Here is a method that does not require recompiling.
It is best if the PHP installation package file exists on the server. If it has been deleted, download the PHP installation file with the same version as shown on the phpinfo page. Here is php-5.2.14.tar.gz
It is recommended to download the Sohu mirror, but the NetEase mirror was not found. The address is: http://mirrors.sohu.com/php/
Connect to the host using ssh tool.
# Download to the /var/www/php5 directory
cd /var/www/php5
wget http://mirrors.sohu.com/php/php-5.2.14.tar.gz
# Unzip
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 can’t find it, use whereis phpize to find it
# After execution, an error was found: 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 completed, a directory of .so files (openssl.so) will be returned. Copy the openssl.so file in this directory to the extension_dir you specified in php.ini (find: extension_dir = in the php.ini file). My directory here is var/www/php5/lib/php/extensions
# Edit the php.ini file and add
at the end of the file
extension=openssl.so
# Just restart Apache
/usr/local/apache2/bin/apachectl restart
Okay, openssl support is now successfully added.
However, Gmail’s troubles don’t end there. Gmail’s current SMTP and POP3 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.phpmailer and smtp add property Is_SSL
public $Is_SSL = false;
2. Pass to the smtp object in the SmtpConnect method in phpmailer
$this->smtp-> Is_SSL = $this-> Is_SSL ;
3. The Connect method in smtp adds
before the fsockopen call.
if($this->is_ssl){ $host = 'ssl://'.$host; }
The last step is the usage method. Remember to call the phpmailer class, which is not in the code.
Copy code
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = 'smtp.gmail.com'; // Your business 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 = '***'; //Email 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);
Copy code
That’s it for the code part. Don’t forget to make the corresponding settings in gmail.
After completing the above three steps, you can freely use phpmailer to send gmail emails.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/765063.htmlTechArticle1.Could not authenticate First of all, if you do not use loops, basically the account or password is wrong; if Use a loop to send messages in bulk. Remember to call Sm after the send() method ends...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template