alert("开始发送邮件"); $config = Config('site'); if(isset($data['config'])){ $config = $data['config']; unset($data['config']); } try { $mail = new \Nette\Mail\Message; $mailer = new \Nette\Mail\SmtpMailer( host: $config['mail_smtp_host'], username: $config['mail_smtp_user'], password: $config['mail_smtp_pass'], encryption: \Nette\Mail\SmtpMailer::EncryptionSSL, ); $mail->setFrom($config['mail_from']) ->addTo($data['email']) ->setSubject($data['title']); if($data['body']){ $mail->setHtmlBody($data['body']); }else{ $mail->setHtmlBody($this->getTemplate($data)); } $mailer->send($mail); \support\Log::channel('mail')->alert($data['email']."邮件已经发送"); } catch (\Throwable $th) { \support\Log::channel('mail')->alert('发送邮件出错1:'.$th->getMessage()); \support\Log::channel('mail')->alert(json_encode($data)); } // 无需反序列化 //var_export($data); // 输出 ['to' => 'tom@gmail.com', 'content' => 'hello'] } function getTemplate($data){ $config = Config('site'); $mail_from = $config['mail_from']; $str = '
![]() Thanks for your request! Do not share this code with anyone, even if they claim to be a Codify employee. {$code} Valid within 15 minutes and can only be used once. Need help with anything? connect support |