doushi9474 2015-04-25 10:40
浏览 69
已采纳

在joomla电子邮件中添加html输出

i am trying to set html on the output of the email send by joomla. my file is located in the joomla core. i know i have to add something like ->isHTML(true); but i do not know where and how. here is the code:

class MailtoController extends JControllerLegacy
{
/**
 * Show the form so that the user can send the link to someone.
 *
 * @return  void
 *
 * @since 1.5
 */
public function mailto()
{
    $session = JFactory::getSession();
    $session->set('com_mailto.formtime', time());
    $this->input->set('view', 'mailto');
    $this->display();

}


public function send()
{
    // Check for request forgeries
    JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));

    $app     = JFactory::getApplication();
    $session = JFactory::getSession();
    $timeout = $session->get('com_mailto.formtime', 0);

    if ($timeout == 0 || time() - $timeout < 1)
    {
        JError::raiseNotice(500, JText::_('COM_MAILTO_EMAIL_NOT_SENT'));

        return $this->mailto();
    }

    $SiteName = $app->get('sitename');
    $link     = MailtoHelper::validateHash($this->input->get('link', '', 'post'));

    // Verify that this is a local link
    if (!$link || !JUri::isInternal($link))
    {
        // Non-local url...
        JError::raiseNotice(500, JText::_('COM_MAILTO_EMAIL_NOT_SENT'));

        return $this->mailto();
    }

    // An array of email headers we do not want to allow as input
    $headers = array (
        'Content-Type:',
        'MIME-Version:',
        'Content-Transfer-Encoding:',
        'bcc:',
        'cc:'
    );

    // An array of the input fields to scan for injected headers
    $fields = array(
        'mailto',
        'sender',
        'from',
        'subject',
    );

    /*
     * Here is the meat and potatoes of the header injection test.  We
     * iterate over the array of form input and check for header strings.
     * If we find one, send an unauthorized header and die.
     */
    foreach ($fields as $field)
    {
        foreach ($headers as $header)
        {
            if (strpos($_POST[$field], $header) !== false)
            {
                JError::raiseError(403, '');
            }
        }
    }

    /*
     * Free up memory
     */
    unset ($headers, $fields);

    $email           = $this->input->post->getString('mailto', '');
    $sender          = $this->input->post->getString('sender', '');
    $from            = $this->input->post->getString('from', '');
    $subject_default = JText::sprintf('COM_MAILTO_SENT_BY', $sender);
    $subject         = $this->input->post->getString('subject', $subject_default);

    // Check for a valid to address
    $error = false;

    if (!$email || !JMailHelper::isEmailAddress($email))
    {
        $error = JText::sprintf('COM_MAILTO_EMAIL_INVALID', $email);
        JError::raiseWarning(0, $error);
    }

    // Check for a valid from address
    if (!$from || !JMailHelper::isEmailAddress($from))
    {
        $error = JText::sprintf('COM_MAILTO_EMAIL_INVALID', $from);
        JError::raiseWarning(0, $error);
    }

    if ($error)
    {
        return $this->mailto();
    }

    // Build the message to send
    $msg  = JText::_('COM_MAILTO_EMAIL_MSG');
    $link = $link;
    //$body = sprintf($msg, $SiteName, $sender, $from, $link);
    $body = "<p>Hello Test F,</p><br/><p>Thank you for registering at Deals&offers. Your account is created and activated.</p><br/>You may login to ".$SiteName." using the following username and password:</br><p>Username: ".$sender."</p><p>Password: ".$from."/p><br/><p><b>Note:</b> It is recomended to change your password after first login. ".$link."</p>";

    // Clean the email data
    $subject = JMailHelper::cleanSubject($subject);
    $body    = JMailHelper::cleanBody($body);

    // To send we need to use punycode.
    $from  = JStringPunycode::emailToPunycode($from);
    $from  = JMailHelper::cleanAddress($from);
    $email = JStringPunycode::emailToPunycode($email);

    // Send the email
    if (JFactory::getMailer()->sendMail($from, $sender, $email, $subject, $body) !== true)
    {
        JError::raiseNotice(500, JText::_('COM_MAILTO_EMAIL_NOT_SENT'));

        return $this->mailto();
    }

    JFactory::getApplication()->enqueueMessage('ok!', '');
    $this->input->set('view', 'sent');
    $this->display();
}
}

thank you very much

  • 写回答

1条回答 默认 最新

  • duanlingzei0170 2015-04-25 12:26
    关注

    you can add before body or between subject and body . however, it must be before the submit command !! here is an example of PhpMailler firstly, you need to call the class like this and you can use it

      $this->mail= new PHPMailer();
              $this->mail->IsSMTP(); 
    
    $this->mailIsHTML(true);
    $subject = JMailHelper::cleanSubject($subject);
    $body    = JMailHelper::cleanBody($body);
    

    however if the function is static also you call the function in same class you can call the function by sef command

    self::mailIsHTML(true)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?