Phpmailer Send mail function is very powerful, today's real experience, simply say configuration, I was in thinkphp is used
Configuration steps:
1. Background configuration send mail class, location admin/common/common.php
In
The code is as follows |
Copy Code |
function SendMail ($tomail, $title, $content) { /* Message Setup Information * * $email _set = C (' Email_set '); Vendor (' Phpmailer.class#phpmailer '); Vendor ("Phpmailer.class#smtp"); Optional, otherwise it will be included in the class.phpmailer.php
$mail = new Phpmailer (true); Instantiate the Phpmailer class, true to throw an exception when an error occurs
$mail->issmtp (); Using SMTP $mail->charset = "UTF-8";//Set message encoding $mail->host = $email _set[' Host ']; SMTP Server $mail->smtpdebug = 1; Enable SMTP Debugging 1 = errors 2 = messages $mail->smtpauth = true; Server needs authentication $mail->port = $email _set[' Port ']; Set port $mail->smtpsecure = "SSL"; /* $mail->smtpsecure = "SSL"; $mail->host = "smtp.gmail.com"; $mail->port = 465; */
$mail->username = $email _set[' Email_user ']; User account for SMTP server $mail->password = $email _set[' email_pwd ']; User password for SMTP server $mail->addreplyto ($email _set[' email '), $email _set[' email_name '); Reply to this mailbox when the recipient replies, you can execute the method multiple times if (Is_array ($tomail)) { foreach ($tomail as $m) { $mail->addaddress ($m, ' user '); } }else{ $mail->addaddress ($tomail, ' user '); }
$mail->setfrom ($email _set[' email '), $email _set[' email_name '); $mail->addattachment ('./img/phpmailer.gif '); Add an attachment and repeat the method if there are multiple attachments $mail->subject = $title; The following are the message content related $mail->body = $content; $mail->ishtml (TRUE);
$body = file_get_contents (' tpl.html '); Get HTML page Content $mail->msghtml (Eregi_replace ("[]", ", $body));
return $mail->send ()? True:false; } |
2: Configuration parameters in the configuration file:
The code is as follows |
Copy Code |
/* Mail Settings * * ' Email_set ' =>array ( ' Host ' => ' smtp.163.com ', ' Port ' => ' 25 ', ' Email_user ' => ' liuying ', ' Email_pwd ' => ' 123456 ', ' Email ' => ' liuying@163.com ', ' Email_name ' => ' 86 market network ', ), |
3. Test Send code:
code is as follows |
copy code |
SendMail (' 11234@126.com ', ' hello ', ' I am content '); |