代码之家  ›  专栏  ›  技术社区  ›  Stark Doe

表单提交给用户和管理员-Magento、PHP和Zend Mail

  •  0
  • Stark Doe  · 技术社区  · 7 年前

    我在Magento工作,不熟悉PHP和Zend Mail。

    该表单是之前开发的,旨在将表单提交发送到3个不同的电子邮件地址。电子邮件地址来自“联系人”下的管理部分。

    我想添加一个用户在提交表单后收到的自动响应。

    作为一个新手,我希望你们能帮助我修复代码。提前感谢!

    try {
        foreach($split as $multiemail){
            $mail = new Zend_Mail();
            $mail->setBodyText($rq_msg);
            $mail->setBodyHtml($rq_msg);
            $mail->setFrom($fromEmail, $fromName);
            $mail->addTo($multiemail, $adminName);
            $mail->setSubject('New request from customer: '.$fromName);
            $mail->send();
    
            $mail = new Zend_Mail();
            $mail->setBodyText($cust_msg);
            $mail->setBodyHtml($cust_msg);
            $mail->setFrom('our@email.com');
            $mail->addTo($fromEmail);
            $mail->setSubject('Your request was received, '.$fromName);
            $mail->send();
        }
    } 
    catch(Exception $e) {
        echo $e->getMassage();
    }
    
    Mage::getSingleton('core/session')
        ->addSuccess(Mage::helper('contacts')
        ->__('Your inquiry was submitted and will be responded to 
             as soon as possible. Thank you for contacting us.');
    
    $this->_redirectUrl($request['redirecturl']);
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   bassxzero    7 年前

    您正在循环向用户发送电子邮件。将用户电子邮件移出循环,使其只发生一次。

    <?php
        try {
            foreach ($split as $multiemail) {
                $mail = new Zend_Mail();
                $mail->setBodyText($rq_msg);
                $mail->setBodyHtml($rq_msg);
                $mail->setFrom($fromEmail, $fromName);
                $mail->addTo($multiemail, $adminName);
                $mail->setSubject('New request from customer: ' . $fromName);
                $mail->send();           
            }
    
            $mail = new Zend_Mail();
            $mail->setBodyText($cust_msg);
            $mail->setBodyHtml($cust_msg);
            $mail->setFrom('our@email.com');
            $mail->addTo($fromEmail);
            $mail->setSubject('Your request was received, ' . $fromName);
            $mail->send();
    
        }
        catch (Exception $e) {
            echo $e->getMassage();
        }
    
        Mage::getSingleton('core/session')->addSuccess(Mage::helper('contacts')->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.'));
        $this->_redirectUrl($request[ 'redirecturl' ]);