我使用的是Magento
v1.9.1,安裝了MailGun
插件。Magento - Mailgun插件不發送電子郵件
插件網址: https://www.magentocommerce.com/magento-connect/mailgun-for-email-delivery.html
在這裏你可以看到在管理方面的MailGun
插件:
然後我用下面的代碼來發送測試電子郵件(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(...)
上面的代碼沒有出現。
任何想法如何解決/調試呢?
檢查錯誤日誌 – urfusion
在與上述相同的情況下(但刪除了「die」這一行:「send」),我使用正式的Magento電子郵件測試了電子郵件系統,如訂閱並創建一個帳戶這些電子郵件是通過Mailgun正確發送的。但是當我發送第一個代碼爲「test_email.php」的自定義電子郵件時,則不會通過MailGun發送電子郵件,而是通過默認的smtp中繼。有關如何在自定義電子郵件中使用MailGun的想法? – Angel