public function send()
{
if (null === $this->message->getMessage()) {
$this->message->init();
}
$messageBody = $this->message->getMessage();
$headers = $this->buildHeaders() . $this->message->getEol() . $this->message->getEol();
// Send as group message
if ($this->group) {
mail((string) $this->queue, $this->subject, $messageBody, $headers, $this->params);
// Else, Iterate through the queue and send the mail messages.
} else {
foreach ($this->queue as $rcpt) {
$subject = $this->subject;
$message = $messageBody;
// Set the recipient parameter.
$to = isset($rcpt['name']) ? $rcpt['name'] . " <" . $rcpt['email'] . ">" : $rcpt['email'];
// Replace any set placeholder content within the subject or message.
foreach ($rcpt as $key => $value) {
$subject = str_replace('[{' . $key . '}]', $value, $subject);
$message = str_replace('[{' . $key . '}]', $value, $message);
}
// Send the email message.
mail($to, $subject, $message, $headers, $this->params);
}
}
}
/** * Send user password reset notification * * @param mixed $user * @param string $title * @return void */ public function sendReset($user, $title) { $host = $_SERVER['HTTP_HOST']; $domain = str_replace('www.', '', $host); $newPassword = $this->random(); $user->password = (new Bcrypt())->create($newPassword); $user->save(); $rcpt = ['name' => $user->username, 'email' => $user->email, 'domain' => $domain, 'username' => $user->username, 'password' => $newPassword, 'title' => $title]; $mailTemplate = __DIR__ . '/../../view/mail/forgot.txt'; // Send email verification $mail = new Mail($title . ' (' . $domain . ') - Password Reset', $rcpt); $mail->from('noreply@' . $domain); $mail->setText(file_get_contents($mailTemplate)); $mail->send(); }