2017-02-08 43 views
0

我使用的是Magento v1.9.1,安裝了MailGun插件。Magento - Mailgun插件不發送電子郵件

插件網址: https://www.magentocommerce.com/magento-connect/mailgun-for-email-delivery.html

在這裏你可以看到在管理方面的MailGun插件:

enter image description here

然後我用下面的代碼來發送測試電子郵件(test_email.php):

<?php 
// Invoke the Magento environment 
require_once('app/Mage.php'); 
Mage::app(); 

//Getting the Store E-Mail Sender Name. 
$senderName = Mage::getStoreConfig('trans_email/ident_general/name'); 

//Getting the Store General E-Mail. 
$senderEmail = Mage::getStoreConfig('trans_email/ident_general/email'); 

$customerEmail = "<[email protected]_on_purpose>"; 
$text = "Hello, this is a test."; 

//Sending E-Mail to Customers. 
$mail = Mage::getModel('core/email') 
->setToName($senderName) 
->setToEmail($customerEmail) 
->setBody($text) 
->setSubject('Subject :') 
->setFromEmail($senderEmail) 
->setFromName($senderName) 
->setType('html'); 
try{ 
//Confimation E-Mail Send 
$mail->send(); 
} 
catch(Exception $error) 
{ 
Mage::getSingleton('core/session')->addError($error->getMessage()); 
return false; 
} 
?> 

然後郵件到達我bu它不通過MailGun發送。我知道,因爲收到的電子郵件的標題是應用程序所在的服務器,並且MailGun日誌中不記錄電子郵件。

我認爲MailGun插件只在後端管理區域工作,但在發送電子郵件時沒有被Magento調用。通過將線

./app/code/community/FreeLunchLabs/MailGun/Model/Mailgun.php :

die("Send stopped on file: ./app/code/community/FreeLunchLabs/MailGun/Model/Mailgun.php"); 

我也做了測試修改文件

像:

... 
    public function send($message) { 

     die("Send stopped on file: ./app/code/community/FreeLunchLabs/MailGun/Model/Mailgun.php"); 

     $domain = $message->getStore()->getConfig('mailgun/general/domain'); 
     $apiKey = $message->getStore()->getConfig('mailgun/general/key'); 
     $files = null; 

     if(count($message->getAttachments())) { 
      foreach($message->getAttachments() as $attachment) { 
       $files[] = $attachment; 
      } 
     } 

     $sendResponse = $this->mailgunRequest('messages', $domain, $apiKey, $message->getMessage(), Zend_Http_Client::POST, false, $files); 

     if($message->getStore()->getConfig('mailgun/events/store')) { 
      Mage::getModel('freelunchlabs_mailgun/email')->saveInitialSend($message, $sendResponse); 
     } 

     return $sendResponse; 
    } 

... 

但在運行文件時:test_email.php,stopped message裏面的die(...)上面的代碼沒有出現。

任何想法如何解決/調試呢?

+0

檢查錯誤日誌 – urfusion

+0

在與上述相同的情況下(但刪除了「die」這一行:「send」),我使用正式的Magento電子郵件測試了電子郵件系統,如訂閱並創建一個帳戶這些電子郵件是通過Mailgun正確發送的。但是當我發送第一個代碼爲「test_email.php」的自定義電子郵件時,則不會通過MailGun發送電子郵件,而是通過默認的smtp中繼。有關如何在自定義電子郵件中使用MailGun的想法? – Angel

回答

0

好吧,經過一些嘗試/錯誤實驗後,我發現答案:MailGun擴展名僅適用於transactional emails,如其描述中所述。您不能使用MailGun直接發送自定義電子郵件,就像我的初始代碼:test_email.php。如果你想使用MailGun發送一些定製的郵件,你應該首先創建模板,然後使用該模板就像在下面的代碼,我的ID創建的模板:1只

<?php 
// Invoke the Magento environment 
require_once('app/Mage.php'); 
Mage::app(); 

$templateId = 1; 
$receiveName = "<Your Name Here>"; 
$receiveEmail = "<your email here>"; 

$storeId = Mage::app()->getStore()->getStoreId(); 

$emailTemplate = Mage::getModel("core/email_template")->load($templateId); 

$vars = array(
     "name"  => $receiveName, 
     "email"  => $receiveEmail, 
     "phone"  => "+13052491037", 
     "comment" => "This is my comment: Hello World!" 
); 

$emailTemplate->getProcessedTemplate($vars); 

/* 
echo "<pre>\n"; 
print_r($emailTemplate); 
echo "</pre>\n"; 
die(); 
//*/ 

$emailTemplate->setSenderName(Mage::getStoreConfig("trans_email/ident_general/name", $storeId)); 
$emailTemplate->setSenderEmail(Mage::getStoreConfig("trans_email/ident_general/email", $storeId)); 

$emailTemplate->send($receiveEmail, $receiveName, $vars); 

?> 

希望這有助於人。