作者:丶玛骝 | 来源:互联网 | 2014-06-12 18:37
phpmailer发送邮件是php开发者首选的一个邮件发送插件了,下面我来介绍怎么集成phpmailer到thinkphp框架了,有需要了解的朋友可参考。phpmail...
phpmailer发送邮件是php开发者首选的一个邮件发送插件了,下面我来介绍怎么集成phpmailer到thinkphp框架了,有需要了解的朋友可参考。
phpmailer发送邮件功能很强大,今天真正的体验一下,简单说一下配置,本人是在thinkphp中是用的.
配置步骤:
1.后台配置发送邮件类,位置admin/common/common.php中,代码如下:
- function sendmail($tomail,$title,$content)
- {
-
- $email_set = C('EMAIL_SET');
- Vendor('phpmailer.class#phpmailer');
- Vendor("phpmailer.class#smtp");
-
- $mail = new PHPMailer(true);
-
- $mail->IsSMTP();
- $mail->CharSet ="UTF-8";
- $mail->Host = $email_set['Host'];
- $mail->SMTPDebug = 1;
- $mail->SMTPAuth = true;
- $mail->Port = $email_set['port'];
-
-
-
-
-
-
-
- $mail->Username = $email_set['email_user'];
- $mail->Password = $email_set['email_pwd'];
- $mail->AddReplyTo($email_set['email'],$email_set['email_name']);
- 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->Subject = $title;
-
-
- $mail->Body = $content;
- $mail->IsHTML(true);
-
-
-
-
-
- return $mail->Send()? true:false;
- }
2:配置文件中配置参数,代码如下:
-
- 'EMAIL_SET'=>array(
- 'Host'=> "smtp.163.com",
- 'Port'=>'25',
- 'email_user'=>'liuying',
- 'email_pwd'=>'123456',
- 'email'=>'liuying@163.com',
- 'email_name'=>'86市场网',
- )
3.测试发送代码,代码如下:
sendmail(’11234@126.com‘,‘您好’,‘我是内容’);