Phplist and Phpmailer (combined use) to send mail via Gmail configuration method _php Tips

Source: Internet
Author: User
Tags php introduction word wrap gmail mail gmail password

This article gives an example of how phplist and Phpmailer send mail via gmail. Share to everyone for your reference, specific as follows:

In general, as long as you are not using Gmail mailbox, then use Phplist to send mail as long as the previous "PHP Mail mass system Phplist Configuration method Detailed Summary" configuration is enough. But if you are as unfortunate as I am, you must use Gmail, an SSL-authenticated mailbox, so congratulations, my misfortune is now your lucky, after several days of trying, I finally succeeded in combining Gmail with Phplist. The experience is shared here and I hope it will be useful to you and my comrades in general. In addition, the core of Phplist is Phpmailer, I proposed the solution is mainly around the phpmailer, so the need to use Phpmailer through Gmail to send mail but not successful people can also refer to my method.

First, in accordance with the "PHP Mail mass system Phplist Configuration method Detailed summary of the configuration method through Gmail to send mail, when the test message sent Phplist will report the failure to send a message, in the event log (eventlog) There will be error prompts" Mailer errors: The following from address failed: ... ", which says there is a problem with the sender. Are you already connected to the SMTP server, but there is a problem sending the message? You can experiment with a method that doesn't even connect to the SMTP server: I put the config.php file in the mailbox account password intentionally incorrectly, the result sends the test message still reported the same error, appears to be not connected to the SMTP server at all, this phplist error report too ...

Know that it's not connected to the SMTP server that's the point at the heart of Phplist's e-mail message--Another well-known open-source software Phpmailer.

Online check phpmailer send gmail mail information, found that the old version of the Phpmailer does not support SSL authentication, can not connect the Gmail SMTP server, and this issue has been resolved in the new version of the Phpmailer.

Open Lists/admin/phpmailer/changelog.txt, found that the latest version of the Phplist from the Phpmailer version is 1.73, is 2005 out, indeed not new. So on Phpmailer's official website under the latest 5.1.

I would like to first look at how the new version of Phpmailer to solve the problem of SSL authentication, so I looked at its own some of the documentation, happened to find under Phpmailer_v5.1/docs there is a use_ Gmail.txt, it seems that the official more emphasis on Gmail, a special demo for people to refer to. Open a look is really a complete php page file, basically modify the file name extension, mailbox username and password can be used, but if only so modified, when accessing the test page will be an error, do not know how the official out of the demo can have such a mistake, incredibly will call an undefined function, And there are some unnecessary ingredients. We just want to test if we can send the mail normally, so I'll change it to read:

<?php//example on using Phpmailer with GMAIL include ("class.phpmailer.php"); Include ("class.smtp.php");
    Note, this is optional-gets called from main class if not already loaded $mail = new Phpmailer ();
    $body = "Test";
    $mail->issmtp ();         $mail->smtpauth = true;         Enable SMTP authentication $mail->smtpsecure = "SSL";   Sets the prefix to the Servier $mail->host = "smtp.gmail.com";          Sets GMAIL as the SMTP server $mail->port = 465; Set the SMTP port $mail->username = "myname@gmail.com";      GMAIL username $mail->password = "MyPassword";
    GMAIL password $mail->from = "myname@gmail.com";
    $mail->fromname = "Webmaster";
    $mail->subject = "This is the Subject"; $mail->altbody = "This are the body when user views in plain text format"; Text body $mail->wordwrap = 50;
    Set word wrap $mail->msghtml ($body);$mail->addreplyto ("myname@gmail.com", "webmaster");
    $mail->addaddress ("myname@gmail.com", "the Last"); $mail->ishtml (TRUE); Send As HTML if (! $mail->send ()) {echo "Mailer Error:".
    $mail->errorinfo;
    else {echo "message has been sent";

 }?>

It turns out that when you visit this page, there is still an error, it is really frustrating, the official demo how can not run?

At this time I suddenly think of Phpmailer_v5.1/docs there is a file called Note_for_smtp_debugging.txt, now I do not want to connect to the SMTP server and worry, may wish to look inside the debugging methods provided.

Open the file after reading the first line of light, this is what I need! In fact, the use of the method is also very simple, as long as in

$mail->issmtp ();

Before inserting

$mail->smtpdebug = 1;

You can get more detailed error messages at the same time. That's a good thing, ^_^.

After this modification, I got a more detailed description of the page when I visited it--"SMTP-> error:failed to connect to server:unable to find" Socket transport "SSL"-di D forget to enable it while you configured PHP? (28593608) ".

So I opened my PHP profile (C://windows/php.ini) to search for SSL, and I found an extension on SSL.

; Extension=php_openssl.dll

It was not opened. Remove the ";" before it is used for the annotation, and then restart the server to access the test page use_gmail.php again, still the same error message.

No way, I checked the internet on the PHP and Apache SSL configuration article, found that only the SSL expansion module is not enough to open, but also to configure the OpenSSL, in the Windows environment configuration method is very simple-- Locate the Ssleay32.dll and Libeay32.dll in the PHP installation directory and copy them to the System32 directory under Windows (open Extension=php_openssl.dll in php.ini is necessary). Of course, the comrades who do not want to "pollute" the System32 directory can use the method of modifying the environment variable, just let Ssleay32.dll and Libeay32.dll in the system path. (If you are not using the Winidows operating system, please find a way to configure SSL for your operating system, it should not be difficult to find)

This time again visit use_gmail.php Discovery can be successfully sent!

On this basis, our phplist problem can also be solved: in the new version of Phpmailer class.phpmailer.php and class.smtp.php cover lists/admin/phpmailer in the corresponding file, And then modify the 36 lines in the lists/admin/class.phplistmailer.php.

$this->smtpauth = true;
$this->helo = getconfig ("website");
$this->host = phpmailerhost;

For:

$this->issmtp ();            # Add
$this->smtpauth = true;
$this->smtpsecure = "SSL";       # Add
$this->helo = getconfig ("website");
$this->host = phpmailerhost;
$this->port = 465            # ADD

Where the Phpmailer default port number is 25, is the port number for most SMTP servers, but Gmail uses a port number of 465, so reset it.

More interested in PHP related content readers can view the site topics: "PHP Network Programming Skills Summary", "PHP basic Grammar Introductory Course", "PHP operation Office Document Skills Summary (including word,excel,access,ppt)", " PHP Date and Time usage summary, PHP Introduction to object-oriented Programming, PHP String (String) Usage summary, PHP+MYSQL database Operations Tutorial and PHP Common database operating Skills summary

I hope this article will help you with the PHP program design.

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.