123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace catchAdmin\email\model;
- use catcher\base\CatchModel as Model;
- use PHPMailer\PHPMailer\PHPMailer;
- use PHPMailer\PHPMailer\Exception;
- use PHPMailer\PHPMailer\SMTP;
- use think\facade\Db;
- class Email extends Model
- {
-
- public $name = 'email';
-
- public $field = array(
- 'id',
-
- 'email',
-
- 'status',
-
- 'info',
-
- 'creator_id',
-
- 'created_at',
-
- 'updated_at',
-
- 'deleted_at',
- );
-
- public function getStatusAttr()
- {
- return (string) $this->getData('status');
- }
-
-
- public function setEmail($emails,$title,$body)
- {
- $where= [];
- $where[] = ['type','=','email_config'];
- $Host = Db::name("sys_config")->where($where)->where('field','SmtpHost')->value('fieldValue');
- $Username = Db::name("sys_config")->where($where)->where('field','SmtpUserName')->value('fieldValue');
- $Password = Db::name("sys_config")->where($where)->where('field','SmtpPassword')->value('fieldValue');
- $SMTPSecure = Db::name("sys_config")->where($where)->where('field','SMTPSecure')->value('fieldValue');
- $Port =Db::name("sys_config")->where($where)->where('field','SmtpPort')->value('fieldValue');
- $Name = Db::name("sys_config")->where($where)->where('field','Name')->value('fieldValue');
- $mail = new PHPMailer(true);
- try {
-
- $mail->CharSet ="UTF-8";
- $mail->SMTPDebug = 0;
- $mail->isSMTP();
- $mail->Host = trim($Host);
- $mail->SMTPAuth = true;
- $mail->Username = trim($Username);
- $mail->Password = trim($Password);
- $mail->SMTPSecure = trim($SMTPSecure);
- $mail->Port = trim($Port);
- $mail->setFrom(trim($Username),$Name);
-
-
-
-
-
- foreach($emails as $item)
- {
- $mail->addAddress($item);
- }
-
-
-
- $mail->isHTML(true);
- $mail->Subject = $title;
- $mail->Body = $body;
- $mail->AltBody = '如果邮件客户端不支持HTML则显示此内容';
- $mail->send();
- echo '邮件发送成功';
- } catch (Exception $e) {
- echo '邮件发送失败: ', $mail->ErrorInfo;
- }
-
- }
- }
|