企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
> 项目安装邮件扩展 `composer require phpmailer/phpmailer` ``` ~~~ /** * @param $to * @param string $subject * @param string $content * @return bool * @throws \PHPMailer\PHPMailer\Exception * 发送邮件 */ function send_email($to, $subject = '', $content = ''){ $mail = new PHPMailer\PHPMailer\PHPMailer(); //获取配置 $config= \app\admin\model\general\HhyConfig::configList('email'); $mail->CharSet = 'UTF-8'; //设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码 $mail->isSMTP(); $mail->SMTPDebug = 0; //调试输出格式 //$mail->Debugoutput = 'html'; //smtp服务器 $mail->Host = $config['mail_smtp_host']; //端口 - likely to be 25, 465 or 587 $mail->Port = $config['mail_smtp_port']; if ($mail->Port == '465') { $mail->SMTPSecure = 'ssl'; }// 使用安全协议 //Whether to use SMTP authentication $mail->SMTPAuth = true; //发送邮箱 $mail->Username = $config['mail_smtp_user']; //密码 $mail->Password = $config['mail_smtp_pass']; //Set who the message is to be sent from $mail->setFrom($config['mail_from'], $config['mail_smtp_name']); //回复地址 //$mail->addReplyTo('replyto@example.com', 'First Last'); //接收邮件方 if (is_array($to)) { foreach ($to as $v) { if(is_email($v)){ $mail->addAddress($v); } } } else { if(is_email($to)){ $mail->addAddress($to); } } $mail->isHTML(true);// send as HTML //标题 $mail->Subject = $subject; //HTML内容转换 $mail->msgHTML($content); return $mail->send(); } ~~~ ~~~ function is_email($user_email) { $chars = "/^([a-z0-9+_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,6}\$/i"; if (strpos($user_email, '@') !== false && strpos($user_email, '.') !== false) { if (preg_match($chars, $user_email)) { return true; } else { return false; } } else { return false; } } ~~~ ```