PHP uses Pear's own mail class library to send mail _php tips

Source: Internet
Author: User
Tags getmessage pear php programming

The example in this article describes how PHP uses the Mail class library with pear to send mail. Share to everyone for your reference. Specifically as follows:

Here, you can use Pear's own mail class library to send mail, and the Pear Install command to install the corresponding library

BODY = "<a href= ' http://www.baidu.com/' target= ' _blank ' > dot i regenerate password </a>";
SENDMAIL_SMTP ("xxxxxxxx@qq.com", ' Test ', $body);
 function Sendmail_smtp ($smtpemailto, $mailsubject, $mailbody) {//error_reporting (7);
 Require_once ' mail.php ';
 Require_once ' mail/mime.php ';
 $from = ' admin@xxx.com ';
 $to = $smtpemailto;
 $password = ' xxxxxx '; $mail _config=array ("host" => "smtp.ym.163.com", "Port" =>25, "auth" =>true, "username" => $from, "pa
 ssWOrd "=> $password," from "=> $from,);
 $hdrs = Array (' From ' => $from, ' to ' => $to,//mail address ' Subject ' => $mailsubject);
 $mime = new Mail_mime ();
 $mime->settxtbody ($text);
 Add attachments//$mime->addhtmlimage (' php.gif ', ' image/gif ', ' 12345 ', true); $mime->_build_params[' html_charset '] = "utf-8";//Set encoding format $mime->_build_params[' head_charset '] = "utf-8";
 Set the encoding format $mime->sethtmlbody ($mailbody);
 $body = $mime->get ();
 $hdrs = $mime->headers ($hdrs);
 $mail = mail::factory (' smtp ', $mail _config);$SUCC = $mail->send ($to, $hdrs, $body);
  if (Pear::iserror ($SUCC)) {//echo ' Email sending failed: '. $SUCC->getmessage (); $err = ' Email sending failed: '.
  $SUCC->getmessage (); $content = $to. " \\t ". Date (' y-m-d h:i:s ')."
 \\t ". $err." \\r\\n "; else {//$content = $to. \\t ". Date (' y-m-d h:i:s ')."
  \\t Email sent succesfully \\r\\n ";
 return true; }
}

I hope this article will help you with your PHP programming.

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.