After a long time, finally in the Gmail test success, if there is a successful QQ or 163 mailbox test, convenient words, trouble to tell detailed configuration.
Phpmailer:
Phpmailer:https://github.com/phpmailer/phpmailer
First, the basic requirements
- Web Access is normal (Apache can access it normally)
- PHP is set up correctly (Sockets support, OpenSSL two are set to enable)
- Gmail settings, allowing less secure apps: Enabled
Can write a simple sentence to test: info.php
<? PHP Phpinfo ();? >
Unzip the downloaded Phpmailer to the web directory, my directory structure is as follows: (the main file is circled in the red box, in the directory than you extracted after the file, please do not mind)
Second, gmailer.php set
The need to mark as ***xxx*** is changed to its own information.
<?PHPrequire' Phpmailerautoload.php '; With Gmailer in the Phpmailer folder$mail=NewPhpmailer;$mail->smtpdebug = 1;//Enable verbose debug output$mail->ISSMTP ();//Set Mailer to use SMTP$mail->host = ' smtp.gmail.com ';//Specify main and backup SMTP servers$mail->smtpauth =true;//Enable SMTP Authentication$mail->username = ' ***[email protected]*** ';//SMTP username$mail->password = ' ***your_gmail_password*** ';//SMTP Password$mail->smtpsecure = ' SSL ';//Enable TLS encryption, ' SSL ' also accepted$mail->port = 465;//TCP port to connect to$mail->setfrom (' ***[email protected]*** ', ' Mailer ');//ADD set from ID$mail->addaddress (' ***starnight_cyber at Foxmail. com*** ', ' Receiver ');//Add a recipient$mail->addaddress (' ***neverthinkaboutit at 163. com*** ', ' Receiver ');//Add a recipient$mail->subject = ' Helo, it is a test! ';$mail->body = ' This is the HTML message Body <b>in bold!</b> ';$mail->altbody = ' The body in plain text for non-html mail clients ';if(!$mail-Send ()) { Echo' Message could not being sent. '; Echo' Mailer Error: '.$mail-ErrorInfo;} Else { Echo' Message has been sent ';}?>
Access page: http://localhost/phpmailer/gmailer.php, you will get the following output, showing that the send is correct. (The picture quality is too poor to display)
Here is the recipient's case: (after the message is sent, you need to wait a minute or so to see the message, with Gmail will be faster)
Finally, attach: IMAP/SMTP/POP3 address of gmail,qmail,163 mailbox
Welcome to my message contact ...
Phpmailer sending mail