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.