在这里,我将尽量做到透彻和简短。我目前是第一次在Joomla工作,但我之前已经开发过了。我使用的是Joomla 3.4。我想做的是:一个用户通过一个特定的页面注册我们的时事通讯,这个页面将他们引导到一个优惠券。下一页向他们显示优惠券,并在URL中有一个电子邮件标签(即& email =' email '),我试图在一个模块中编写代码,以解析出该电子邮件,并将优惠券的副本自动发送到该用户的电子邮件。
当任何用户订阅时,我不能使用一般的自动电子邮件,因为只有从该特定页面注册的用户才能获得优惠券。我已经关闭了所有的文本过滤,正在使用基本的模块编辑器。当我保存模块时,代码在编辑框中显示得很好。当我查看页面的源代码时,脚本标记仍然在那里,但代码都是空白的。我现在已经进入phpmyadmin,可以直接在那里编辑模块。现在,脚本显示得很好。
我尝试了许多不同的修复,包括添加一个jQuery($)函数load,以绕过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,这些问题的答案让我摆脱了很多麻烦。我在任何地方都找不到这个问题的答案。耽误您时间,实在对不起!
发布于 2015-05-09 17:23:21
将以下内容放入您的模块中。
<?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>';
}注意:根据你将这段代码放在哪里,你可能需要一个像这样的扩展来让它运行。
https://stackoverflow.com/questions/30133792
复制相似问题