public function searchEMail($address) { $sql = "SELECT `emailid`, `email`, `gpgfingerprint`, `lastSend` FROM `emails` WHERE `email` = '" . $this->escape($address) . "'"; $result = $this->getResult($sql, array($this, "parseEMail")); if ($result->getCount() > 0) { return $result->fetchRow(); } $email = new EMail($this); $email->setEMail($address); $email->setGPGFingerprint(null); $email->setLastSend(null); $email->save(); return $email; }
/** * @param string $toEmail * @param string $subject * @param string $textPlain * @param string $textHtml * * @throws \Exception */ public static function sendWithLog($toEmail, $subject, $textPlain, $textHtml = '') { $mailer = new static(\Yii::$app->params); $messageId = explode('@', \Yii::$app->params['mailFromEmail']); $messageId = uniqid() . '@' . $messageId[1]; $exception = null; try { $message = $mailer->createMessage($subject, $textPlain, $textHtml, $messageId); $status = $mailer->send($message, $toEmail); } catch (\Exception $e) { $status = EMail::STATUS_DELIVERY_ERROR; $exception = $e; } $obj = new EMail(); $obj->toEmail = $toEmail; $obj->subject = $subject; $obj->text = $textPlain; $obj->dateSent = date('Y-m-d H:i:s'); $obj->status = $status; $obj->messageId = $messageId; $obj->save(); if ($exception) { /** @var \Exception $exception */ throw new \Exception($exception->getMessage()); } if (YII_ENV == 'test') { \Yii::$app->session->setFlash('email', 'E-Mail sent to: ' . $toEmail); } }