|
@@ -0,0 +1,86 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\common\library;
|
|
|
+
|
|
|
+use think\Config;
|
|
|
+
|
|
|
+class Email
|
|
|
+{
|
|
|
+
|
|
|
+ * 发送邮件
|
|
|
+ * @param string $mTo 收件人
|
|
|
+ * @param string $subject 邮件主题
|
|
|
+ * @param string $content 邮件内容(html)
|
|
|
+ * @param string $fromNic 发件人昵称
|
|
|
+ * @param string $toNic 收件人昵称
|
|
|
+ */
|
|
|
+ public function sendMail($mTo='',$subject='',$content='',$fromNic='',$toNic='')
|
|
|
+ {
|
|
|
+ $site = Config::get("site");
|
|
|
+ $re = Vendor('phpmailer.phpmailer.PHPMailerAutoload');
|
|
|
+
|
|
|
+ $mail = new \PHPMailer ();
|
|
|
+
|
|
|
+
|
|
|
+ $mail->isSMTP();
|
|
|
+ $mail->Host = $site['mail_smtp_host'];
|
|
|
+ $mail->SMTPAuth = true;
|
|
|
+ $mail->Username = $site['mail_smtp_user'];
|
|
|
+ $mail->Password = $site['mail_smtp_pass'];
|
|
|
+ switch ($site['mail_verify_type'])
|
|
|
+ {
|
|
|
+ case 1:
|
|
|
+ $mail->SMTPSecure = 'tls';
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ $mail->SMTPSecure = 'ssl';
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ $mail->SMTPSecure = '';
|
|
|
+ }
|
|
|
+ $mail->Port = $site['mail_smtp_port'];
|
|
|
+ $mail->setFrom($site['mail_from'], $fromNic);
|
|
|
+ $mail->addAddress($mTo, $toNic);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $mail->isHTML(true);
|
|
|
+ $mail->Subject = $subject;
|
|
|
+ $mail->Body = $content;
|
|
|
+
|
|
|
+
|
|
|
+ switch ($site['mail_type'])
|
|
|
+ {
|
|
|
+ case 1:
|
|
|
+ if(!$mail->send()) {
|
|
|
+ $sendResult['text'] = $mail->ErrorInfo;
|
|
|
+ $sendResult['data'] = false;
|
|
|
+ return $sendResult;
|
|
|
+ } else {
|
|
|
+ $sendResult['text'] ='smtp发送成功';
|
|
|
+ $sendResult['data'] = true;
|
|
|
+ return $sendResult;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ $headers = 'MIME-Version: 1.0' . "\r\n";
|
|
|
+ $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
|
|
|
+ $headers .= 'To: '.$toNic.' <'.$mTo.'>' . "\r\n";
|
|
|
+ $headers .= 'From: '.$fromNic.' <'.$site['mail_from'].'>' . "\r\n";
|
|
|
+ $sendResult['data'] = mail($mTo, $subject, $content, $headers);
|
|
|
+ if ($sendResult['data']) {
|
|
|
+ $sendResult['text'] ='mail函数发送成功';
|
|
|
+ }else{
|
|
|
+ $sendResult['text'] ='mail函数发送失败';
|
|
|
+ }
|
|
|
+ return $sendResult;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ $sendResult['data'] = false;
|
|
|
+ $sendResult['text'] ='已关闭邮件发送';
|
|
|
+ return $sendResult;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|