Summarize the frequently asked questions of PHPmailer group sending Gmail. phpmailer group sending gmail_PHP tutorial-php Tutorial

Source: Internet
Author: User
Tags gmail mail gmail password
Summarize the common problems of PHPmailer group-sending Gmail, and phpmailer group-sending gmail. Summarize the frequently asked questions about PHPmailer group-sending Gmail. you may encounter many frequently asked questions when phpmailer group-sending gmail. The following summarizes some frequently asked questions, to solve the common problems of PHPmailer group sending Gmail in a large summary, 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://

Connect to the host using ssh tools.

# Download to/var/www/php5 directory cd/var/www/php5wget 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 '; // your enterprise Post Office domain name $ mail-> SMTPAuth = true; // turn on SMTP authentication $ mail-> SMTPSecure = "tls "; $ mail-> Username = '*** @'; $ 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:

PHPMailer - SMTP (Gmail) basic test<?php//error_reporting(E_ALL);error_reporting(E_STRICT);date_default_timezone_set('America/Toronto');require_once('../class.phpmailer.php');//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded$mail = new PHPMailer();$body = file_get_contents('contents.html');$body = eregi_replace("[\]",'',$body);$mail->IsSMTP(); // telling the class to use SMTP$mail->Host = ""; // SMTP server$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)// 1 = errors and messages// 2 = messages only$mail->SMTPAuth = true; // enable SMTP authentication$mail->SMTPSecure = "ssl"; // sets the prefix to the servier$mail->Host = ""; // sets GMAIL as the SMTP server$mail->Port = 465; // set the SMTP port for the GMAIL server$mail->Username = "***"; // GMAIL username$mail->Password = "***"; // GMAIL password$mail->SetFrom('****', 'First Last');$mail->AddReplyTo("***","First Last");$mail->Subject = "PHPMailer Test Subject via smtp (Gmail), basic";$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test$mail->MsgHTML($body);$address = "***";$mail->AddAddress($address, "John Doe");$mail->AddAttachment("images/phpmailer.gif"); // attachment$mail->AddAttachment("images/phpmailer_mini.gif"); // attachmentif(!$mail->Send()) {echo "Mailer Error: " . $mail->ErrorInfo;} else {echo "Message sent!";}?> 

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

When using PHPmailer to send emails to Gmail, you will encounter many common problems. The following summarizes some common problems for you...

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: 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.