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

Php 在joomla电子邮件中添加html输出,php,html,joomla3.0,Php,Html,Joomla3.0,我正试图在joomla发送的电子邮件的输出上设置html。我的文件位于joomla核心。 我知道我必须添加->isHTML(true);但我不知道在哪里,如何。 代码如下: class MailtoController extends JControllerLegacy { /** * Show the form so that the user can send the link to someone. * * @return void * * @since 1.5 */ pub

我正试图在joomla发送的电子邮件的输出上设置html。我的文件位于joomla核心。 我知道我必须添加->isHTML(true);但我不知道在哪里,如何。 代码如下:

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();
}
}
类MailtoController扩展了JControllerLegacy
{
/**
*显示表单,以便用户可以将链接发送给其他人。
*
*@返回无效
*
*@自1.5
*/
公共函数mailto()
{
$session=JFactory::getSession();
$session->set('com_mailto.formtime',time());
$this->input->set('view','mailto');
$this->display();
}
公共函数send()
{
//检查请求是否伪造
JSession::checkToken()或jexit(JText::(('jinfalid_TOKEN');
$app=JFactory::getApplication();
$session=JFactory::getSession();
$timeout=$session->get('com\u mailto.formtime',0);
如果($timeout==0 | | time()-$timeout<1)
{
JError::raiseNotice(500,JText::((“COM_MAILTO_EMAIL_NOT_SENT”);
返回$this->mailto();
}
$SiteName=$app->get('SiteName');
$link=mailtoheloper::validateHash($this->input->get('link','post'));
//验证这是本地链接
if(!$link | |!JUri::isInternal($link))
{
//非本地url。。。
JError::raiseNotice(500,JText::((“COM_MAILTO_EMAIL_NOT_SENT”);
返回$this->mailto();
}
//我们不希望允许作为输入的电子邮件标题数组
$headers=数组(
'内容类型:',
'MIME版本:',
'内容传输编码:',
“密件抄送:”,
“抄送:”
);
//用于扫描注入头的输入字段数组
$fields=数组(
“mailto”,
“发件人”,
“从”,
“主题”,
);
/*
*这是头部注射试验的肉和土豆。我们
*迭代表单输入数组并检查标题字符串。
*如果我们找到一个,发送一个未经授权的头,然后死亡。
*/
foreach($fields作为$field)
{
foreach($headers作为$header)
{
if(strpos($\u POST[$field],$header)!==false)
{
杰罗:拉塞尔罗(403,);
}
}
}
/*
*释放内存
*/
未设置($headers,$fields);
$email=$this->input->post->getString('mailto','');
$sender=$this->input->post->getString('sender','');
$from=$this->input->post->getString('from','');
$subject\u default=JText::sprintf('COM\u MAILTO\u SENT\u BY',$sender);
$subject=$this->input->post->getString('subject',$subject\u默认值);
//检查有效的收件人地址
$error=false;
如果(!$email | |!JMailHelper::isEmailAddress($email))
{
$error=JText::sprintf('COM\u MAILTO\u EMAIL\u INVALID',$EMAIL);
JError::raiseWarning(0,$error);
}
//检查有效的发件人地址
if(!$from | |!JMailHelper::isEmailAddress($from))
{
$error=JText::sprintf('COM\u MAILTO\u EMAIL\u INVALID',$from);
JError::raiseWarning(0,$error);
}
如果($error)
{
返回$this->mailto();
}
//构建要发送的消息
$msg=JText::((“COM_MAILTO_EMAIL_msg”);
$link=$link;
//$body=sprintf($msg、$SiteName、$sender、$from、$link);
$body=“您好,测试F,


感谢您在交易和优惠网站注册。您的帐户已创建并激活。


您可以使用以下用户名和密码登录到“$SiteName.”使用以下用户名和密码:
用户名:“.$sender.”

密码:“.$from.”/p>
注意:建议您在首次登录后更改密码。$link; //清理电子邮件数据 $subject=JMailHelper::cleanSubject($subject); $body=JMailHelper::cleanBody($body); //要发送,我们需要使用punycode。 $from=JStringPunycode::emailToPunycode($from); $from=JMailHelper::cleanAddress($from); $email=JStringPunycode::emailToPunycode($email); //发送电子邮件 if(JFactory::getMailer()->sendMail($from,$sender,$email,$subject,$body)!==true) { JError::raiseNotice(500,JText::((“COM_MAILTO_EMAIL_NOT_SENT”); 返回$this->mailto(); } JFactory::getApplication()->enqueueMessage('ok!',''); $this->input->set('view','sent'); $this->display(); } }

非常感谢

您可以在主体之前或主体与主体之间添加。但是,它必须在提交命令之前!! 这里是phpmailer的一个例子,首先,你需要像这样调用这个类,你可以使用它

  $this->mail= new PHPMailer();
          $this->mail->IsSMTP(); 

$this->mailIsHTML(true);
$subject = JMailHelper::cleanSubject($subject);
$body    = JMailHelper::cleanBody($body);
但是,如果函数是静态的,也可以在同一类中调用该函数 您可以通过sef命令调用该函数

self::mailIsHTML(true)