Use pear's own mail class library to send emails. You can use the pear install command to install the corresponding library.
- $body = "Click me to regenerate 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 = 'xxxxxx';
-
- $mail_config=array(
- "host"=>"smtp .ym.163.com",
- "port"=>25,
- "auth"=>true,
- "username"=>$from,
- "password"=>$password,
- "from" =>$from,
- );
-
- $hdrs = array(
- 'From'=>$from,
- 'To' => $to, //receiving address
- 'Subject'=>$mailsubject
- );
-
- $mime = new Mail_mime();
- //$mime->setTXTBody($text);
- //Add attachment
- //$mime->addHTMLImage('php.gif','image /gif','12345',true);
- $mime->_build_params['html_charset'] = "utf-8";//Set the encoding format
- $mime->_build_params['head_charset'] = "utf -8";//Set 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." rn" ;
- }
- else
- {
- //$content = $to."t".date('Y-m-d H:i:s')."t Email sent succesfully rn" ;
- return true;
-
- }
-
- }
Copy code
|