PHP to use the Phpmailer plug-in to achieve gmail send mail

Source: Internet
Author: User
Tags php language port number

Hpmailer is a mail-sending class dedicated to the PHP language, powerful and rich in PHP's own single mail () function. Support for SMTP, accessories, etc. Phpmailer complies with LGPL authorization and can be downloaded free of charge.
Download Address: Http://sourceforge.net/projects/phpmailer/files/phpmailer%20for%20php5_6/PHPMailer%20v5.1/PHPMailer_v5.1.zip/download
Use the method (only to say the message, the function of the message is drifting over):

The code is as follows Copy Code
issmtp ();
  $mail-> Smtpauth = true; SMTP requires authentication
  $mail-> smtpsecure = ' SSL '; SMTP authentication method
  $mail-> Port = 465; SMTP port number
  $mail-> Username = "username@gmail.com"; Registered Gmail user's mailbox (can be used with your Gmail mailbox)
  $mail-> Password = "Password"; Password
  $mail-> Host = ' smtp.gmail.com '; The outgoing server
  $mail->ishtml (TRUE);//whether to enable sending of HTML messages, default to False,
  $mail-> from = ' username@gmail.com '; Sender's mailbox, use your Gmail mailbox can be
  $mail-> FromName = ' Mailer '; Your name,
  $mail-> Subject = ' mail title '; Mail title
  $mail-> BODY = "Hello world"; Message content, support HTML code
  $mail-> AddAddress (' name@anydomain.com ', ' the ' last '); Recipient mailbox and name
 if (! $mail-> Send ()) {
 echo $mail-> ErrorInfo;
 }

is usually according to the above configuration can send mail through the designated SMTP server, but the personal test settings above can only use 163,126 of SMTP to send mail, such as Qq,gmail sent out! Google search for n long, finally found the following method can successfully send mail through Gmail, of course, including: QQ, Sina, Sohu, etc. (Yahoo can't pass, seemingly yahoo Default SMTP did not open, have to open their one called ' Mail Reminder ' function before you open smtp/ POP3)
Here's the workaround: just find the following code in class.phpmailer.php (which may be slightly different depending on the version of the download):

The code is as follows Copy Code
if (eregi (. +):([0-9]+) $ ', $hosts [$index], $hostinfo)] {
$host = $hostinfo [1];
$port = $hostinfo [2];
} else {
$host = $hosts [$index];
$port = $this-> Port;
}

Change to (no version will be changed to the following content):

The code is as follows Copy Code
if (Eregi (^#) ([a-z]+://)? [ ^:]+):(d+) #i ', $hosts [$index], $hostinfo)} {
$host = $hostinfo [1];
$port = $hostinfo [3];
} else {
$host = $hosts [$index];
$port = $this-> Port;
}

After a few changes I hope you can also smoothly through Gmail to send e-mail messages (of course, to be able to send mail under win, but also to install SMTP in IIS and in PHP with the support of OpenSSL extension). Finally tested, this modification will be able to smoothly through the 126163qqgmailsinasohu SMTP send mail

Related Article

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.