步骤:
1.下载类库PHPMailer,下载地址:https://github.com/blue7wings/ShareCode/tree/master/PHPMailer;
2.解压置于下面路径:
3.控制层函数:
//参数依次为:收邮件人邮箱地址,姓名,邮件主题,邮件内容,成功提示信息。
public function sendmail($sendto_email, $user_name,$subject, $bodyurl,$message)
{
Vendor('Zend.PHPMailer.classphpmailer');
$mail = new PHPMailer();
$mail->SMTPDebug=false ;
$mail->IsSMTP(); // send via SMTP
$mail->Host = "smtp.163.com"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "***"; // SMTP username 注意:普通邮件认证不需要加 @域名 这里是我的163邮箱
$mail->Password = "******"; // SMTP password 在这里输入邮箱的密码
$mail->From = "*****@163.com"; // 发件人邮箱
$mail->FromName = $user_name; // 发件人
$mail->CharSet = "UTF-8"; // 这里指定字符集! 指定UTF-8后邮件的标题和发件人等等不会乱码,如果是GB2312标题会乱码
$mail->Encoding = "base64";
$mail->AddAddress($sendto_email, $user_name); // 收件人邮箱和姓名
// $mail->SetFrom('axx@xxx.com', 'youle有限公司');
$mail->AddReplyTo("youle@163.com", 'youle有限公司');
//$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 =$bodyurl ;
$mail->AltBody = "text/html";
if (!$mail->Send())
{
$mail->ClearAddresses();
echo "邮件错误信息: " . $mail->ErrorInfo;
exit;
}
else
{
$mail->ClearAddresses();
// $this->assign('waitSecond', 6);
$this->success($message);
}
}
4.函数调用:
$this->sendmail($sendto_email, $user_name,$subject, $bodyurl,$message);
参考链接:http://www.cnblogs.com/wenzichiqingwa/archive/2013/03/12/2956168.html