网站有很多地方都会用到发送邮箱:下面是介绍thinkphp3.2.3+phpmailer实现网站发送邮箱!
只需要配置好相关的信息就可以发送邮箱了!
在之前发布过:发送邮件Swift Mailer代替PHPmail有兴趣的朋友可以看看
首先我们需要下载:phpmailer类库 下载地址:https://github.com/PHPMailer/PHPMailer
将下载下来的phpmailer类库放在 Core\Library\Vendor目录中
QQ邮箱端口设置
163邮箱端口
在config.php配置文件设置配置信息 /*======================== 邮件配置 ==========================*/ 'MAIL_SMTP' => 'TRUE',//启用SMTP认证 'MAIL_HOST' => 'smtp.qq.com',//邮件服务器 smtp.163.com 'MALL_PORT' => '465',//端口 'MAIL_SMTPAUTH' => 'TRUE', 'MAIL_SECURE' => 'tls', 'MAIL_CHARSET' => 'utf-8',//字符集 'MAIL_USERNAME' => '972581428@qq.com',//账号 'MAIL_PASSWORD' => '***************',//密码 'MAIL_ISHTML' => 'TRUE',//HTML
在Common\function.php 创建一个发送邮箱函数
/** * 发送邮箱 * @param [type] $to [发件人邮箱] * @param [type] $subject [自定义内容] * @param [type] $content [发送内容] */ function sendMail($to, $subject, $content) { vendor('phpmailer.class#phpmailer'); $mail = new phpmailer(); if (C('MAIL_SMTP')) { $mail->IsSMTP(); } $mail->Host = C('MAIL_HOST'); $mail->SMTPAuth = C('MAIL_SMTPAUTH'); $mail->Username = C('MAIL_USERNAME'); $mail->Password = C('MAIL_PASSWORD'); $mail->SMTPSecure = C('MAIL_SECURE'); $mail->CharSet = C('MAIL_CHARSET'); $mail->From = C('MAIL_USERNAME'); $mail->AddAddress($to); $mail->FromName = '小柯'; $mail->IsHTML(C('MAIL_ISHTML')); $mail->Subject = $subject; $mail->Body = $content; if (!$mail->Send()) { return FALSE; } else { return TRUE; } }
下面来使用它发送邮箱:
$email = I('post.a_c_email');//收件人邮箱 $content = "感谢你的来信!祝你美好一天";//发送内容 //使用 sendMail 函数来发送邮箱 SendMail($emai,'您在玄玄博客上的评论有了新的回复',$content);
以上就是phpmailer发送邮箱,如果发送失败请检查你的邮箱是否设置
如果没有开启请先开启再试试!!!!