1

I use custom form for FAQ and I would like when customer submists form, it would also generate mail and send it to certain email address.

<button class="button" title="Send" type="submit" >
<span><span><?php echo Mage::Helper('faq')->__('Send')?></span></span>
</button>

Same way you can use ->addBcc('em@ail.com')?

This is complete submit.phtml code:

    <div class="mc_submit_question">
<h4 class="title"><?php echo Mage::Helper('faq')->__('Add more Questions please') ?>:</h4>

<?php 
    $faqs = array();
    $collection = Mage::getModel('faq/faq')->getCollection()->addStoreFilter(Mage::app()->getStore()->getId())->addEnableFilter('1');
?>

    <form action="<?php echo $this->getUrl('faq/submit/save')?>" name="myForm"  method="post" onsubmit="return(validate());">
        <div class="mc_faq_field">
            <?php echo Mage::Helper('faq')->__('Select a Subject')?>:<p>
            <select name = "category">
                <option ><?php echo Mage::Helper('faq')->__('---Select Subject---')?></option>
        <?php 
                foreach ($collection as $faq)
                {
                    echo '<option>';
                    echo $faq->getFaqname();
                    echo '</option>';
                }
        ?>
            </select>
        </div>

        <div class="mc_faq_field">
            <?php echo Mage::Helper('faq')->__('Question')?>:<p>
            <textarea name = "question" rows="8" cols="100"></textarea>
        </div>

        <!-- insert code here -->
        <?php
            $_product_submit_question = "";
            $_product_submit_question = $this->getRequest()->getParam('qpro');
            if($_product_submit_question != ""){
        ?>
        <div class="mc_faq_code_mail">
            <?php echo Mage::Helper('faq')->__('Your Email:')?><p>
            <input type="text" name ="customer_email" value=""></input>
        </div>

        <div class="mc_faq_code">
            <!-- <h4><?php //echo Mage::Helper('faq')->__('Product:')?></h4> -->
            <input type="hidden" name ="product_id" value="<?php echo $_product_submit_question; ?>"></input>
        </div>

        <div class="mc_faq_code">
            <input type="hidden" name ="is_customer" value="1"></input>
        </div>
        <?php } ?>

        <!-- end insert code here -->      

        <div class="mc_faq_code">
            <?php
                $im = imagecreate(60, 20);
                $bg = imagecolorallocate($im, 0 , 0, 0); 
                $textcolor = imagecolorallocate($im, 255, 255, 255);
                $random=rand(1000,9999);
                imagestring($im, 10, 10, 2, $random , $textcolor);
                $filenametemp="media".DS."gif".time().".gif";
                ImageGIF($im, $filenametemp); 
                $ImageData = file_get_contents($filenametemp); 
                $ImageDataEnc = base64_encode($ImageData); 
                unlink($filenametemp);      
            ?>
            <?php echo Mage::Helper('faq')->__('Security Code')?>:<p>
            <input type="text" maxlength="4" name ="code"></input>

            <img alt="<?php echo $random ?>" src="data:image/gif;base64,<?php echo $ImageDataEnc?>"">
            <input type="hidden" name="codetest" id="codemd5" value="<?php echo $random?>"/>

        </div>

        <div class="box_bt">
            <button class="button" title="Pošlji" type="submit" >
                <span><span><?php echo Mage::Helper('faq')->__('Send')?></span></span>
            </button>
            <button class="button" title="Povrni" type="reset">
                <span><span><?php echo Mage::Helper('faq')->__('Reset')?></span></span>
            </button>
        </div>
    </form>

</div>

<script type="text/javascript">
<!--
// Form validation code will come here.
function validateEmail()
{
   var emailID = document.myForm.customer_email.value;
   atpos = emailID.indexOf("@");
   dotpos = emailID.lastIndexOf(".");
   if (atpos < 1 || ( dotpos - atpos < 2 )) 
   {
       document.myForm.customer_email.focus() ;
       return false;
   }
   return( true );
}

function validate()
{
   if( document.myForm.category.value == "---Select Subject---" )
   {
     alert( "Prosimo, če vnesete kategorijo." );
     return false;
   }

   if( document.myForm.question.value == "" )
   {
     alert( "Prosimo, če vnesete vaše vprašanje." );
     document.myForm.question.focus() ;
     return false;
   }
   if( document.myForm.customer_email.value == "" )
   {
     alert( "Prosimo, če vnesete e-mail naslov." );
     document.myForm.customer_email.focus() ;
     return false;
   }
   else {
        var emailID = document.myForm.customer_email.value;
        atpos = emailID.indexOf("@");
        dotpos = emailID.lastIndexOf(".");
        if (atpos < 1 || ( dotpos - atpos < 2 )) 
        {
            alert( "Prosimo, če vnesete veljaven e-mail naslov." );
            document.myForm.customer_email.focus() ;
            return false;
        }

   }

   if( document.myForm.code.value == "" )
   {
        alert( "Prosimo, če prepišete varnostno kodo." );
        document.myForm.code.focus() ;
        return false;
   }

   return( true );
}
//-->
</script>
2

The ->addBcc() function needs to be called on an object with a class of either Mage_Core_Model_Email_Template, Mage_Core_Model_Email_Info or Zend_Mail.

Have a look how this is used in the core, for example in app/code/core/Mage/Core/Model/Email/Template/Mailer.php:

public function send()
{
    /** @var $emailTemplate Mage_Core_Model_Email_Template */
    $emailTemplate = Mage::getModel('core/email_template');
    // Send all emails from corresponding list
    while (!empty($this->_emailInfos)) {
        $emailInfo = array_pop($this->_emailInfos);
        // Handle "Bcc" recipients of the current email
        $emailTemplate->addBcc($emailInfo->getBccEmails());
        // Set required design parameters and delegate email sending to Mage_Core_Model_Email_Template
        $emailTemplate->setDesignConfig(array('area' => 'frontend', 'store' => $this->getStoreId()))
            ->setQueue($this->getQueue())
            ->sendTransactional(
                $this->getTemplateId(),
                $this->getSender(),
                $emailInfo->getToEmails(),
                $emailInfo->getToNames(),
                $this->getTemplateParams(),
                $this->getStoreId()
        );
    }
    return $this;
}

As I've seen in your code above you're calling a saveAction from your modules' controller. So you can implement it there (for example) and not in your .phtml file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.