0

我正在编写一个邮件功能作为 joomla 3 中的一个模块。电子邮件工作正常,但是当我重新加载页面并插入不同的电子邮件并发送时,它似乎通过 JRequest::getVar 函数返回了上一封电子邮件。有没有办法解决这个问题?提前致谢..

这是我使用的代码:

    <?php

    defined('_JEXEC') or die('Direct Access to this location is not allowed.');

    require_once(dirname(__FILE__) . DS . 'helper.php');

    //declaration
    $input = JFactory::getApplication()->input;

    $form_send = $input->get('form_send', 'notsend');
    $fanme = $input->get('firstName');
    $lname = $input->get('lastinput');
    $email = $input->get('email', 0 , 'STRING');

    $mail=false;
    $emailexist=false;

    echo '<script>
        var php_var = "chk is first:'.$email.'";
        alert(php_var);
        </script>';
    switch ($form_send) {

        case 'send':

           if ((is_null($fanme) || is_null($lname) || is_null($email)) || (!filter_var($email, FILTER_VALIDATE_EMAIL))) {
                echo '<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Fields are empty or not valid.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br></div>';
            } else {

                    $mail = ModLittleContactHelper::SendMail($email, $fanme, $lname);
                    echo '<script>
                    var php_var = "chk when mail sending:'.$email.'";
                    alert(php_var);
                    </script>';
                   $input = JFactory::getApplication();//i have tried $app also
                   $input ->setUserState('mod_mycontact.email', null);

                }
                //echo $respond
                if (!$mail) {
                    echo 'Error sending email:';
                    require(JModuleHelper::getLayoutPath('mod_myecontact', 'default_tmpl'));
                }else{

                    require(JModuleHelper::getLayoutPath('mod_mycontact', 'sendok_tmpl'));
                    break;
                }


        default:

            require(JModuleHelper::getLayoutPath('mod_littlecontact', 'default_tmpl'));
            unset($var);
    }
    ?>

@Mario 这是帮助代码:

    class ModLittleContactHelper{
        public function SendMail($email, $fname, $lname) {


        $body = "<p style='font-family:arial;font-size:20px;'>Hi  " . $fname . " " . $lname . ",</p>";
        $body.="<p style='font-family:arial;font-size:20px;'>Welcome to Crowd Logistics! Please verify your email address below.</p><br/><br/>";
        $body.= "<hr><br/>";
        $body.= "<p style='align:center;background-color:#40B3DF;font-family:arial;color:#FFFFFF;font-size:20px;'><a href='http://suriyaarachchi.com/crowdlogistics/index.php?option=com_content&view=article&id=192' target='_blank'>Verify " . $email . "</a></p>";
        $body.= "<br/><hr><br/>";
        $body.="<p style='text-align:right;font-family:arial;font-size:20px;'>Or, paste this link into your browser:<br/>";
        $body.= "http://crowdlogistics/index.php?option=com_content&view=article&id=192<br/><br/>";
        $body.= "Thanks.<br/>";
        $body.= "CrowdLogistics</p><br/>";


        $mailer = & JFactory::getMailer();
                $mailer->setSender('info@crowdlogistics.com');
                $mailer->addRecipient($email);
                $mailer->setSubject('Mail from CrowdLogistics - Confirm your email');
                $mailer->setBody($body);
                $mailer->IsHTML(true);
                $send = & $mailer->Send();



        return $send;
      }
4

3 回答 3

0

首先,JRequestJ3 中不推荐使用 class。你应该使用JInput

$input = JFactory::getApplication()->input;
$your_var = $input->get('your_var');

然后,关于电子邮件,您可能需要在成功(已发送邮件)时取消设置会话变量,或者换句话说,当您不再需要它们时。

$app = JFactory::getApplication();
// your_var is the variable you want to unset
$app->setUserState('mod_your_module.your_var', null);

希望能帮助到你

于 2013-08-12T12:40:01.550 回答
0

由于您尝试在 Joomla 3 上运行您的代码,因此存在一些问题。在你的代码下面,更正了我能够更正的地方。现在你必须在你的模块环境中使用被实例化的类来测试它(换句话说,在你的模块中测试下面的代码)。

<?php

defined('_JEXEC') or die('Direct Access to this location is not allowed.');

require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'helper.php');

//declaration
$doc = JFactory::getDocument();
$app = JFactory::getApplication();
$input = $app->input;

$form_send = $input->get('form_send', 'notsend');
$fanme = $input->get('firstName');
$lname = $input->get('lastinput');
$email = $input->get('email', 0 , 'STRING');

$mail=false;
$emailexist=false;

$doc->addScriptDeclaration('
var php_var = "chk is first:'.$email.'";
alert(php_var);
');

switch ($form_send) {

case 'send':

    if ((is_null($fanme) || is_null($lname) || is_null($email)) || (!filter_var($email, FILTER_VALIDATE_EMAIL))) {
        echo '<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Fields are empty or not valid.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br></div>';
    } else {

        $mail = ModLittleContactHelper::SendMail($email, $fanme, $lname);
        $doc->addScriptDeclaration('
                var php_var = "chk when mail sending:'.$email.'";
                alert(php_var);');
        $app->setUserState('mod_littlecontact.email', null);

    }
    //echo $respond
    if (!$mail) {
        echo 'Error sending email:';
        require(JModuleHelper::getLayoutPath('mod_littlecontact', 'default_tmpl'));
        break;
    }else{
        require(JModuleHelper::getLayoutPath('mod_littlecontact', 'sendok_tmpl'));
        break;
    }

default:

    require(JModuleHelper::getLayoutPath('mod_littlecontact', 'default_tmpl'));
    unset($var);
}
?>
于 2013-08-12T17:26:36.960 回答
0

你可以使用这个代码

$email = $input->get('email', 0 , 'STRING','');

默认值的第四个参数,

于 2013-08-12T17:27:46.173 回答