/** * Tests the addReplyTo method. * * @covers JMail::addReplyTo * * @return void */ public function testAddReplyTo() { $recipient = '*****@*****.**'; $name = 'test_name'; $expected = array('*****@*****.**' => array('*****@*****.**', 'test_name')); $this->object->addReplyTo($recipient, $name); $this->assertThat($expected, $this->equalTo(TestReflection::getValue($this->object, 'ReplyTo'))); }
/** * @param JMail $mail */ private function set_from(&$mail) { $emailhelper = new FoxEmailHelper($this->Params); /** @var Joomla\Registry\Registry $config */ $config = JComponentHelper::getParams("com_foxcontact"); // Set a default value $default = (object) array("select" => "admin", "email" => "", "name" => ""); $submitteremailfrom = $config->get("submitteremailfrom", $default); $from = $emailhelper->convert($submitteremailfrom); $mail->setSender($from); $submitteremailreplyto = $config->get("submitteremailreplyto", $default); $replyto = $emailhelper->convert($submitteremailreplyto); // In Joomla 1.7 From and Reply-to fields is set by default to the Global admin email // but a call to setSender() won't change the Reply-to field $mail->ClearReplyTos(); $mail->addReplyTo($replyto[0], $replyto[1]); }
public static function sendEmail($from, $fromName, $replyTo, $toEmail, $cc, $bcc, $subject, $content, $isHtml) { jimport('joomla.mail.mail'); $mail = new JMail(); $mail->setSender(array($from, $fromName)); if (isset($replyTo)) { $mail->addReplyTo($replyTo); } $mail->addRecipient($toEmail); if (isset($cc)) { $mail->addCC($cc); } if (isset($bcc)) { $mail->addBCC($bcc); } $mail->setSubject($subject); $mail->setBody($content); $mail->IsHTML($isHtml); $ret = $mail->send(); $log = Logger::getInstance(); $log->LogDebug("E-mail with subject " . $subject . " sent from " . $from . " to " . $toEmail . " " . serialize($bcc) . " result:" . $ret); return $ret; }
/** * This function is used to override the send function in Joomla */ public static function getMailer($mailing, $html = 0) { $fromname = empty($mailing->fromname) ? trim($GLOBALS[JNEWS . 'sendmail_name']) : trim($mailing->fromname); $fromemail = empty($mailing->fromemail) ? trim($GLOBALS[JNEWS . 'sendmail_email']) : trim($mailing->fromemail); $frombounce = empty($mailing->frombounce) ? trim($GLOBALS[JNEWS . 'sendmail_from']) : trim($mailing->frombounce); if (empty($fromemail)) { $my = JFactory::getUser(); $userSender = jNews_Subscribers::getUsers('gid', '50', $my->id); $fromemail = $userSender[0]->email; if (empty($fromemail)) { jnews::printM('no', 'The sender email needs to be specified in the configuration.'); return false; } } if (empty($frombounce)) { $frombounce = $fromemail; } $attachments = $mailing->attachments; $images = $mailing->images; $conf = JFactory::getConfig(); $frombounceName = $fromname ? $fromname : $conf->get('config.fromname'); if (empty($fromemail)) { $fromemail = trim($conf->get('config.mailfrom')); } if (empty($fromname)) { $fromname = trim($conf->get('config.fromname')); } jimport('joomla.mail.mail'); $phpmailerPath = JPATH_LIBRARIES . DS . 'phpmailer' . DS; $mail = new JMail(); $mail->PluginDir = $phpmailerPath; $mail->SetLanguage('en', $phpmailerPath . 'language' . DS); $mail->WordWrap = 150; // $mail->addCustomHeader("X-Mailer: ".JNEWS_JPATH_LIVE); // $mail->addCustomHeader("X-MessageID: $mailing->id"); if ($GLOBALS[JNEWS . 'mail_format'] == '1') { $mail->Encoding = 'base64'; } if ($GLOBALS[JNEWS . 'minisendmail']) { $frombounceName = ''; } if (!empty($frombounce)) { if (version_compare(JVERSION, '3.0.0', '<')) { $mail->addReplyTo(array($frombounce, $frombounceName)); } else { $mail->addReplyTo(array($frombounce)); } JRequest::setVar('bounceBackEmail', $frombounce); } $mail->From = trim($fromemail); if ($GLOBALS[JNEWS . 'minisendmail']) { $mail->FromName = ''; } else { $mail->FromName = $fromname; } $mail->Sender = trim($GLOBALS[JNEWS . 'sendmail_from']); if (empty($mail->Sender)) { $mail->Sender = ''; } switch ($GLOBALS[JNEWS . 'emailmethod']) { case 'mail': $mail->IsMail(); break; case 'sendmail': $mail->IsSendmail(); $mail->Sendmail = $GLOBALS[JNEWS . 'sendmail_path'] ? $GLOBALS[JNEWS . 'sendmail_path'] : $conf->get('config.sendmail'); break; case 'smtp': $mail->IsSMTP(); $mail->Host = $GLOBALS[JNEWS . 'smtp_host'] ? $GLOBALS[JNEWS . 'smtp_host'] : $conf->get('config.smtphost'); $mail->Port = $GLOBALS[JNEWS . 'smtp_port'] ? $GLOBALS[JNEWS . 'smtp_port'] : $conf->get('config.smtpport'); $mail->SMTPSecure = $GLOBALS[JNEWS . 'smtp_secure'] ? $GLOBALS[JNEWS . 'smtp_secure'] : ''; if ((bool) $GLOBALS[JNEWS . 'smtp_auth_required']) { $mail->SMTPAuth = $GLOBALS[JNEWS . 'smtp_auth_required']; $mail->Password = $GLOBALS[JNEWS . 'smtp_password']; $mail->Username = $GLOBALS[JNEWS . 'smtp_username']; } break; default: $mail->Mailer = $conf->get('config.mailer'); break; } if (!empty($attachments)) { foreach ($attachments as $attachment) { if (basename($attachment) !== 'index.html') { $mail->AddAttachment(JNEWS_JPATH_ROOT_NO_ADMIN . $GLOBALS[JNEWS . 'upload_url'] . DS . basename($attachment)); } } } switch (substr(strtoupper(PHP_OS), 0, 3)) { case "WIN": $mail->LE = "\r\n"; break; case "MAC": case "DAR": $mail->LE = "\r"; default: break; } return $mail; }