This article mainly introduces the method of sending mails using the mail class library that comes with pear in PHP. The example analyzes the installation of pear and the implementation skills of mail, which is very simple and practical, for more information about how to use the mail class library that comes with pear in PHP, see the example below. Share it with you for your reference. The details are as follows:
Here, you can use the mail class library provided by pear to send emails. you can use the pear install command to install the corresponding Library.
Body = "click my new password"; 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 = 'xxxx'; $ mail_config = array ("host" => "smtp.ym.163.com ", "port" => 25, "auth" => true, "username" => $ from, "password" => $ password, "from" => $ from ,); $ hdrs = array ('from' => $ From, 'to' => $ To, // recipient address 'subobject' => $ mailsubject ); $ mime = new Mail_mime (); // $ mime-> setTXTBody ($ text); // add an attachment // $ mime-> addHTMLImage('php.gif ', 'image/GIF ', '20140901', true); $ mime-> _ build_params ['HTML _ charset'] = "UTF-8 "; // Set the 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 = $. "\ t ". date ('Y-m-d H: I: s '). "\ t ". $ err. "\ r \ n";} else {// $ content = $. "\ t ". date ('Y-m-d H: I: s '). "\ t Email sent succesfully \ r \ n"; return true ;}}
I hope this article will help you with php programming.