2017-10-06 129 views
0

我正在Magento工作,PHP和Zend Mail是新的。表單提交給用戶和管理員 - Magento,PHP和Zend郵件

該表格之前已經開發,旨在將表單提交發送到3個不同的電子郵件地址。電子郵件地址從「聯繫人」下的管理員部分中提取。

我想添加用戶在提交表單後收到的自動回覆。

它的工作原理,但問題是用戶收到每個表單提交3個單獨的自動電子郵件。我相信你的親會看到爲什麼會立即看到下面的代碼。

作爲一個新手,我希望你們/ gals可以幫助我解決代碼問題。提前致謝!

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('[email protected]'); 
     $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']); 

回答

0

您正在向用戶發送循環電子郵件。將用戶電子郵件移到循環之外,以便只發生一次。

<?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('[email protected]'); 
     $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' ]); 
+0

非常棒的作品很棒。非常感謝您的時間和精力,bassxzero。 –