My phpmailer_v5.1 is used

Source: Internet
Author: User
Tags word wrap server port

<?PHP/** * Example script using Phpmailer with exceptions enabled* @package phpmailer* @version $Id $*/require_once'/class.phpmailer.php ';require_once'/class.smtp.php '; Try {    $mail=NewPhpmailer (true);//New instance, with exceptions enabled    $body=file_get_contents(' contents.html '); $body=Preg_replace(‘/\\\\/‘,‘‘,$body);//Strip Backslashes    $mail-&GT;ISSMTP ();//Tell the class to use SMTP    $mail->smtpauth =true;//Enable SMTP authentication    $mail->port = 25;//set the SMTP server port    $mail->host = "smtp.163.com";//SMTP Server    $mail->username = "1585358****@163.com";//SMTP Server username    $mail->password = "*******";//SMTP Server password//$mail->issendmail (); tell the class to use Sendmail    $mail->addreplyto ("1585358****@163.com", "First Last"); $mail->from = "1585358****@163.com"; $mail->fromname = "First Last"; $to= "309407*** @qq. com"; $mail->addaddress ($to); $mail->subject = "First Phpmailer Message"; $mail->altbody = "To view the message, please use an HTML compatible email viewer!";//Optional, comment out and test    $mail-WordWrap= 80;//Set word wrap    $mail->msghtml ($body); $mail->ishtml (true);//Send As HTML    $mail-Send (); Echo' Message has been sent. ';} Catch(phpmailerexception$e) {    Echo $e-errormessage ();}?>

using PHP to send mail, you can use Phpmailer. Phpmailer is a PHP function pack for sending e-mail so how does Phpmailer work? The first step, of course, is to download the Phpmailer package, which has two versions, a PHP4 version, and PHP5/6 version of the download after the appropriate download, see there are many files, in fact, most of them do not use and then enter the test to see Testemail.php file Here is an example code similar to<?PHP/** * Example script using Phpmailer with exceptions enabled* @package phpmailer* @version $Id $*/require‘.. /class.phpmailer.php ';Try {$mail=NewPhpmailer (true);//New instance, with exceptions enabled$body=file_get_contents(' contents.html ');//What to send$body=Preg_replace(‘/\\\\/‘,‘‘,$body);//Strip Backslashes$mail-&GT;ISSMTP ();//Tell the class to use SMTP$mail->smtpauth =true;//Enable SMTP authentication$mail->port = 25;//set the SMTP server port$mail->host = "smtp.163.com";//SMTP Server$mail->username = "[email protected]";//SMTP Server username$mail->password = "*********";//fill in your own email password//$mail->issendmail ();//Tell the class to use Sendmail$mail->addreplyto ("[Email protected]", "First Last");$mail->from = "[email protected]";//Sender Mailbox$mail->fromname = "small white";//Sender$to= "[Email protected]";//Recipient$mail->addaddress ($to);$mail->subject = "First Phpmailer Message";$mail->altbody = "To view the message, please UseAn HTML compatible email viewer! ";//optional, comment out and test$mail->wordwrap = n;//Set word wrap$mail->msghtml ($body);$mail->ishtml (TRUE);//Send As HTML$mail->send (); Echo ' Message has been sent. '; catch (Phpmailerexception$e) {echo$e->errormessage ();}? > The above code, there is note that the comparison of the important need to carefully fill out the SMTP server can refer to the WordPress send a workaround This article note: 1. If error: Could not execute:/var/qmail/bin/ SendMail then you need to put the configuration file in the$mail->issendmail (); Comment out 2. If you're using a space error: SMTP error:could not connect to SMTP host then you need to modify the class.smtp.php$this->smtp_conn = @fsockopen instead$this->smtp_conn = @pfsockopen because there is a lot of space to disable Fsockopen! Follow the above steps, your mail should have been sent successfully in fact Phpmailer package we really use the files only class.phpmailer.php and class.smtp.php

<?PHP/** * Example script using Phpmailer with exceptions enabled* @package phpmailer* @version $Id $*/require_once'/class.phpmailer.php ';require_once'/class.smtp.php '; Try {    $mail=NewPhpmailer (true);//New instance, with exceptions enabled//$body = file_get_contents (' contents.html '); $body = preg_replace ('/\\\\/', ' ', $body); Strip backslashes    $mail-&GT;ISSMTP ();//Tell the class to use SMTP    $mail->smtpauth =true;//Enable SMTP authentication    $mail->port = 25;//set the SMTP server port    $mail->host = "smtp.163.com";//SMTP Server    $mail->username = "1585358****@163.com";//SMTP Server username    $mail->password = "**********";//SMTP Server password//$mail->issendmail (); tell the class to use Sendmail    $mail->addreplyto ("1585358****@163.com", "First Last"); $mail->from = "1585358****@163.com"; $mail->fromname = "First Last"; $to= "****** @qq. com"; $mail->addaddress ($to); $mail->subject = "First Phpmailer Message"; $mail->body= "This is my test email."; $mail->altbody = "To view the message, please use an HTML compatible email viewer!";//Optional, comment out and test    $mail-WordWrap= 80;//set Word wrap//$mail->charset = "UTF-8";//Character Set//$mail->msghtml ($body);    $mail->ishtml (true);//Send As HTML    $mail-Send (); Echo' Message has been sent. ';} Catch(phpmailerexception$e) {    Echo $e-errormessage ();}?>
<?PHPrequire("class.phpmailer.php");//The downloaded file must be placed in the directory where the file is located$mail=NewPhpmailer ();//set up a mail sending class$address=$_post[' Address '];$mail-&GT;ISSMTP ();//send using SMTP mode$mail->charset= ' UTF-8 ';//set character encoding for messages$mail->host = "mail.xxxxx.***";//your enterprise Post office domain name$mail->smtpauth =true;//enable the SMTP authentication feature$mail->port = "* * *";//SMTP Port$mail->username = * * * @xxxx. * * *;//Post Office User name (please fill in the full email address)$mail->password = "******";//Post Office Password$mail->from = * * * @xxxx. * * *;//Email Sender Email Address$mail->fromname = "Your name";$mail->addaddress ("$address", "");//The recipient address can be replaced with any email message you want to receive, in the format addaddress ("Recipient Email", "Recipient Name")//$mail->addreplyto ("", ""), or $mail AddAttachment ("/var/tmp/file.tar.gz"); Add attachment//$mail->ishtml (TRUE); Set email format to HTML//whether HTML is used$mail->subject = "phpmailer test mail";//message Header$mail->body = "Hello, this is Test mail";//Message Content$mail->altbody = "The body in plain text for non-html mail clients";//additional information, you can omitif(!$mail-Send ()) {Echo"The message failed to send. <p> ";Echo"Cause of error:".$mail-errorinfo;Exit;}Echo"Mail sent successfully";?>

My phpmailer_v5.1 is used

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.