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