在tp系統文件下的Extend->Vendor->Zend下放置phpmailer文件包,並把phpmailer類改名。
看目錄:
然后參考tp手冊:
so...我的導入方法代碼為:
Vendor('Zend.PHPMailer.classphpmailer');
完整的郵件發送代碼:
首先是發送方法:
public function sendmail($sendto_email, $user_name, $subject, $bodyurl) { Vendor('Zend.PHPMailer.classphpmailer'); $mail = new PHPMailer(); $mail->IsSMTP(); // send via SMTP $mail->Host = "你的郵件服務域名"; // SMTP servers $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = "XXXX"; // SMTP username 注意:普通郵件認證不需要加 @域名 $mail->Password = "******"; // SMTP password $mail->From = "axx@xxx.com"; // 發件人郵箱 $mail->FromName = "管理員"; // 發件人 $mail->CharSet = "utf-8"; // 這里指定字符集! $mail->Encoding = "base64"; $mail->AddAddress($sendto_email, $user_name); // 收件人郵箱和姓名 $mail->SetFrom('axx@xxx.com', 'XXXXXXX有限公司'); $mail->AddReplyTo("axx@xxx.com", 'xxxxxxxx有限公司'); //$mail->WordWrap = 50; // set word wrap 換行字數 //$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment 附件 //$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); $mail->IsHTML(true); // send as HTML // 郵件主題 $mail->Subject = $subject; // 郵件內容 $mail->Body = '<html><head> <meta http-equiv="Content-Language" content="zh-cn"/> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> </head> <body> <div style="width:60%;padding:30px 20px;background:#F9F9F9;"> <span style="font-weight:bold;font-size:16px;">Hi,' . $user_name . '</span><br/> 歡迎您注冊<b>XXX公司網站</b><br/> 請點擊下面的連接完成注冊(有效期一小時):<br/> ' . $bodyurl . '<br/> <font style="color:#999;">如果以上鏈接無法點擊,請將上面的地址復制到你的瀏覽器(如IE)的地址欄完成激活</font><br/> http://www.XXX.com </div> </body> </html> '; $mail->AltBody = "text/html"; if (!$mail->Send()) { $mail->ClearAddresses(); echo "郵件錯誤信息: " . $mail->ErrorInfo; exit; } else { $mail->ClearAddresses(); // $this->assign('waitSecond', 6); // $this->success("注冊成功,系統已經向您的郵箱:{$sendto_email}發送了一封激活郵件!請您盡快激活~~<br />"); $this->redirect('sendhtml', array('send' => 5,'email'=>$sendto_email)); } }
其次調用發送方法:
$this->sendmail($_POST['email'], $_POST['nickname'], $subject, $bodyurl);