public function getPreparedMailHandler($toEmail, $toName = '', array $headers = array(), $fromEmail = '', $fromName = '', $returnPath = '')
{
$contents = $this->prepareMailContents();
if (!$contents)
{
return false;
}
$contents = $this->wrapMailContainer($contents['subject'], $contents['bodyText'], $contents['bodyHtml'], $toEmail, $toName);
$mailObj = new Zend_Mail('utf-8');
$mailObj->setSubject($contents['subject'])
->setBodyText($contents['bodyText'])
->addTo($toEmail, $toName);
if ($contents['bodyHtml'] !== '')
{
$mailObj->setBodyHtml($contents['bodyHtml']);
}
$options = XenForo_Application::get('options');
if (!$fromName)
{
$fromName = ($options->emailSenderName ? $options->emailSenderName : $options->boardTitle);
}
if ($fromEmail)
{
$mailObj->setFrom($fromEmail, $fromName);
}
else
{
$mailObj->setFrom($options->defaultEmailAddress, $fromName);
}
if ($returnPath)
{
$mailObj->setReturnPath($returnPath);
}
else
{
$bounceEmailAddress = $options->bounceEmailAddress;
if (!$bounceEmailAddress)
{
$bounceEmailAddress = $options->defaultEmailAddress;
}
$mailObj->setReturnPath($bounceEmailAddress);
}
foreach ($headers AS $headerName => $headerValue)
{
if (isset(self::$_headerMap[strtolower($headerName)])) {
$func = self::$_headerMap[strtolower($headerName)];
$mailObj->$func($headerValue);
}
else
{
$mailObj->addHeader($headerName, $headerValue);
}
}
return $mailObj;
}