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(); // 使用SMTP $mail->Host = trim($Host); // SMTP服务器 $mail->SMTPAuth = true; // 允许 SMTP 认证 $mail->Username = trim($Username); // SMTP 用户名 即邮箱的用户名 $mail->Password = trim($Password); // SMTP 密码 部分邮箱是授权码(例如163邮箱) $mail->SMTPSecure = trim($SMTPSecure); // 允许 TLS 或者ssl协议 $mail->Port = trim($Port); // 服务器端口 25 或者465 具体要看邮箱服务器支持 $mail->setFrom(trim($Username),$Name); //发件人 //$mail->addAddress('aaaa@126.com', 'Joe'); // 收件人 //$mail->addAddress('ellen@example.com'); // 可添加多个收件人 //$mail->addReplyTo('xxxx@163.com', 'info'); //回复的时候回复给哪个邮箱 建议和发件人一致 //$mail->addCC('cc@example.com'); //抄送 //$mail->addBCC('bcc@example.com'); //密送 foreach($emails as $item) { $mail->addAddress($item); } //发送附件 // $mail->addAttachment('../xy.zip'); // 添加附件 // $mail->addAttachment('../thumb-1.jpg', 'new.jpg'); // 发送附件并且重命名 $mail->isHTML(true); // 是否以HTML文档格式发送 发送后客户端可直接显示对应HTML内容 $mail->Subject = $title; $mail->Body = $body; $mail->AltBody = '如果邮件客户端不支持HTML则显示此内容'; $mail->send(); echo '邮件发送成功'; } catch (Exception $e) { echo '邮件发送失败: ', $mail->ErrorInfo; } } }