/**
* @param string $EventName
* @todo add port settings
* @return boolean
*/
public function send($EventName = '')
{
$this->formatMessage($this->emailTemplate->toString());
$this->fireEvent('BeforeSendMail');
if (c('Garden.Email.Disabled')) {
throw new Exception('Email disabled', self::ERR_SKIPPED);
}
if (c('Garden.Email.UseSmtp')) {
$this->PhpMailer->isSMTP();
$SmtpHost = c('Garden.Email.SmtpHost', '');
$SmtpPort = c('Garden.Email.SmtpPort', 25);
if (strpos($SmtpHost, ':') !== false) {
list($SmtpHost, $SmtpPort) = explode(':', $SmtpHost);
}
$this->PhpMailer->Host = $SmtpHost;
$this->PhpMailer->Port = $SmtpPort;
$this->PhpMailer->SMTPSecure = c('Garden.Email.SmtpSecurity', '');
$this->PhpMailer->Username = $Username = c('Garden.Email.SmtpUser', '');
$this->PhpMailer->Password = $Password = c('Garden.Email.SmtpPassword', '');
if (!empty($Username)) {
$this->PhpMailer->SMTPAuth = true;
}
} else {
$this->PhpMailer->isMail();
}
if ($EventName != '') {
$this->EventArguments['EventName'] = $EventName;
$this->fireEvent('SendMail');
}
if (!empty($this->Skipped) && count($this->PhpMailer->getAllRecipientAddresses()) == 0) {
// We've skipped all recipients.
throw new Exception('No valid email recipients.', self::ERR_SKIPPED);
}
$this->PhpMailer->setThrowExceptions(true);
if (!$this->PhpMailer->send()) {
throw new Exception($this->PhpMailer->ErrorInfo);
}
return true;
}