public function sendMail($email = '', $name = '', $subject, $body, $key = 'gaodun') { if (!$email) { return FALSE; } //发送邮件的主要设置 $mail = new PHPMailer(FALSE); $account = $this->setEmailAccount($key); try { $mail->IsSMTP(); //启用smtp协议 $mail->SMTPAuth = TRUE; $mail->SMTPKeepAlive = TRUE; $mail->CharSet = "utf-8"; $mail->SMTPSecure = $account['md']; $mail->Port = $account['port']; $mail->Host = $account['host']; $mail->Username = $account['email']; $mail->Password = $account['pwd']; $mail->SetFrom($account['email'], '高顿实习'); $mail->Subject = $subject; $mail->Body = $body; $mail->WordWrap = 50; // set word wrap $mail->MsgHTML($body); $mail->AddReplyTo('*****@*****.**', '高顿实习'); $mail->AddAddress($email, $name ? $name : $email); //设置收件人 $mail->IsHTML(TRUE); if ($mail->Send()) { $info = array('status' => TRUE, 'msg' => C('L_MAIL_SEND_SUCCESS')); // send as HTML } else { $info = array('status' => FALSE, 'msg' => $mail->ErrorInfo); // send as HTM } return $info; } catch (phpmailerException $e) { $info = array('status' => FALSE, 'msg' => $e->errorMessage()); return $info; } }
/** * 发送邮件 * @author 致远<*****@*****.**> */ public function sendMail($email, $subject, $body) { $mail = new PHPMailer(false); try { $mail->IsSMTP(); $mail->SMTPAuth = true; $mail->SMTPKeepAlive = true; $mail->CharSet = "utf-8"; $mail->SMTPSecure = $this->mail_Secure; $mail->Host = $this->mail_Host; $mail->Port = $this->mail_Port; $mail->Username = $this->mail_Username; $mail->Password = $this->mail_Password; $mail->From = $this->mail_Username; $mail->FromName = $this->mail_FromName; $mail->Subject = $subject; $mail->Body = $body; $mail->WordWrap = 50; $mail->MsgHTML($body); $mail->AddReplyTo($this->mail_Replymail, $this->mail_Replyname); $mail->AddAddress($email); $mail->IsHTML(true); if ($mail->Send()) { $info = array('status' => true, 'msg' => C('L_MAIL_SEND_SUCCESS')); } else { $info = array('status' => false, 'msg' => $mail->ErrorInfo); } return $info; } catch (phpmailerException $e) { $info = array('status' => false, 'msg' => $e->errorMessage()); return $info; } }
/** * 用常规方式发送邮件。 */ function send_mail_local($to = '', $subject = '', $body = '', $name = '', $attachment = null) { $from_email = C('MAIL_SMTP_USER'); $from_name = modC('WEB_SITE_NAME', 'OpenSNS开源社交系统', 'Config'); $reply_email = ''; $reply_name = ''; //require_once('./ThinkPHP/Library/Vendor/PHPMailer/phpmailer.class.php');增加命名空间,可以注释掉此行 $mail = new PHPMailer(); //实例化PHPMailer $mail->CharSet = 'UTF-8'; //设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码 $mail->IsSMTP(); // 设定使用SMTP服务 $mail->SMTPDebug = 0; // 关闭SMTP调试功能 // 1 = errors and messages // 2 = messages only $mail->SMTPAuth = true; // 启用 SMTP 验证功能 $mail->SMTPSecure = ''; // 使用安全协议 $mail->Host = C('MAIL_SMTP_HOST'); // SMTP 服务器 $mail->Port = C('MAIL_SMTP_PORT'); // SMTP服务器的端口号 $mail->Username = C('MAIL_SMTP_USER'); // SMTP服务器用户名 $mail->Password = C('MAIL_SMTP_PASS'); // SMTP服务器密码 $mail->SetFrom($from_email, $from_name); $replyEmail = $reply_email ? $reply_email : $from_email; $replyName = $reply_name ? $reply_name : $from_name; if ($to == '') { $to = C('MAIL_SMTP_CE'); //邮件地址为空时,默认使用后台默认邮件测试地址 } if ($name == '') { $name = modC('WEB_SITE_NAME', 'OpenSNS开源社交系统', 'Config'); //发送者名称为空时,默认使用网站名称 } if ($subject == '') { $subject = modC('WEB_SITE_NAME', 'OpenSNS开源社交系统', 'Config'); //邮件主题为空时,默认使用网站标题 } if ($body == '') { $body = modC('WEB_SITE_NAME', 'OpenSNS开源社交系统', 'Config'); //邮件内容为空时,默认使用网站描述 } $mail->AddReplyTo($replyEmail, $replyName); $mail->Subject = $subject; $mail->MsgHTML($body); //解析 $mail->AddAddress($to, $name); if (is_array($attachment)) { // 添加附件 foreach ($attachment as $file) { is_file($file) && $mail->AddAttachment($file); } } return $mail->Send() ? true : $mail->ErrorInfo; //返回错误信息 }