繁体   English   中英

Joomla JMail代码不起作用-Javascript正常工作

[英]Joomla JMail code not working - Javascript works fine

在这里,我将力求全面而简短。 我目前是第一次在Joomla工作,但是我以前有所发展。 我正在使用Joomla 3.4。 我正在尝试做的事情:用户通过将其定向到优惠券的特定页面来注册我们的新闻通讯。 下一页向他们显示了优惠券,并在URL中有一个电子邮件标签(即&email ='email'),我正在尝试在模块中进行编码以解析出该电子邮件,并自动将优惠券的副本发送给该用户的电子邮件。

当任何用户订阅时,我不能使用常规的自动电子邮件,因为只有从该特定页面注册的用户才能获得优惠券。 我已关闭所有文本过滤功能,并正在使用基本模块编辑器。 当我保存模块时,代码在编辑框中显示良好。 当我查看页面源代码时,该脚本标记仍将存在,但是代码将全部为空白。 我现在进入phpmyadmin,可以直接在其中编辑模块。 现在,脚本显示得很好。

我尝试了许多不同的修复程序,包括添加jQuery($)函数负载以绕过mootools的任何问题。 想知道这是否是Javascript的问题,我清除了脚本并发出了一个简单的alert("Testing..."); 在页面上触发的脚本。 这意味着我的完整脚本中一定存在某些无法正常工作的内容。 任何帮助或其他想法都会很棒。 我已经花了整整一天的时间,现在才机智。 这是代码:

<script type="text/javascript">
function get(name){
   if(name=(new RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec (window.location.search))
    $recipient = decodeURIComponent(name[1]);
}

$mailer = JFactory::getMailer();

$config = JFactory::getConfig();
$sender = array(
    $config->get( 'config.mailfrom' ),
    $config->get( 'config.fromname' )
);

$mailer->setSender($sender);

get('email');

$mailer->addRecipient($recipient);

$body = '<h2>Thank you for joining our mailing list!</h2>
    '<div>Here is your coupon for a FREE 8" 1-topping pizza at Goodfellas!'
    '<img src="http://www.goodfellas309.com/main/images/pizzacoupon.jpg" alt="pizza coupont"/></div>';
$mailer->isHTML(true);
$mailer->Encoding = 'base64';
$mailer->setSubject('Your Free Pizza!');
$mailer->setBody($body);

$send = $mailer->Send;
if ( $send !== true ) {
    echo 'Error sending email: ' . $send->__toString();
} else {
    alert("An email with your coupon has been sent to you! Thank you for joining our mailing list!");
}
');
</script>

我什至尝试通过Joomla进行内联PHP解析,并使用以下代码包装javascript:

<?php

$document = JFactory::getDocument();
$document->addScriptDeclaration('
-Javascript here-
');
?>

我一直很喜欢StackOverflow,回答的问题使我摆脱了很多麻烦。 我只是在任何地方都找不到答案。 谢谢你的时间!

将以下内容放入您的模块中。

<?php

// Get the email from the url
$jinput = JFactory::getApplication()->input;
$recipient = $jinput->get('email', '', 'string');

$mailer = JFactory::getMailer();

$config = JFactory::getConfig();
$sender = array(
    $config->get( 'config.mailfrom' ),
    $config->get( 'config.fromname' )
);

$mailer->setSender($sender);

$mailer->addRecipient($recipient);

$body = '<h2>Thank you for joining our mailing list!</h2>'
        .'<div>Here is your coupon for a FREE 8" 1-topping pizza at Goodfellas!'
        .'<img src="http://www.goodfellas309.com/main/images/pizzacoupon.jpg" alt="pizza coupont"/></div>';

$mailer->isHTML(true);
$mailer->Encoding = 'base64';
$mailer->setSubject('Your Free Pizza!');
$mailer->setBody($body);

$send = $mailer->Send;
if ( $send !== true ) {
    echo '<script type="text/javascript">Error sending email: ' . $send->__toString() . '</script>';
} else {
    echo '<script type="text/javascript">alert("An email with your coupon has been sent to you! Thank you for joining our mailing list!");</script>';
}

注意: 根据您放置此代码的位置,您可能需要像这样的扩展名才能使php运行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM