2016-11-30 30 views
-1

偶爾發送郵件失敗,PrestaShop的Mail::send功能。我使用外部郵件服務器,那裏的負責人告訴我,沒有收到發送任何郵件的請求(但我覺得這很奇怪)。所以,我做了一個小記錄器執行以下操作:在PrestaShop 1.6調試Swift郵件程序1.6

if (!Mail::send()) 
    // logging details here here.. 

Mail::send回報false正確。現在我想知道原因。因此我想在SwiftMailer中記錄關於連接的信息。有人能給我任何線索如何以簡單的莊園解決這個問題(如果可能的話,不要使用SwiftMailer插件)。

斯威夫特梅勒版本:3.3.2

回答

2

如果設置$die參數去true你將導致腳本停止,併爲客戶帶來不良的體驗,而購買和管理,同時改變訂單狀態,等您應檢查以下內容:

  1. 檢查電子郵件發送特定電子郵件模板失敗。如果屬實,則可能會遇到模板結構,傳遞的參數,HTML呈現等問題。
  2. 在Prestashop日誌中記錄Mail::Send函數中的每個錯誤。所以你應該在那裏檢查它。你可以知道每一個可能的錯誤identifyng這種代碼內部功能Mail::SendTools::dieOrLog(Tools::displayError('Error: invalid SMTP server or SMTP port'), $die);
  3. 具體斯威夫特異常記錄,此代碼:PrestaShopLogger::addLog('Swift Error: ' . $e->getMessage(), 3, null, 'Swift_Message');所以它應該出現在的Prestashop日誌了。
  4. 無論如何,Swift有他自己的登錄類Swift_Log_DefaultLog。你可以在\tools\swift\Swift\Log\DefaultLog.php找到它。您可以修改adddump函數以將日誌保存到特定文件或類似文件。

祝你好運。

1

設置$die參數真正顯示錯誤。您將需要_PS_MODE_DEV_設置爲true才能看到它。

/** 
* Send Email 
* 
* @param int $id_lang Language ID of the email (to translate the template) 
* @param string $template Template: the name of template not be a var but a string ! 
* @param string $subject Subject of the email 
* @param string $template_vars Template variables for the email 
* @param string $to To email 
* @param string $to_name To name 
* @param string $from From email 
* @param string $from_name To email 
* @param array $file_attachment Array with three parameters (content, mime and name). You can use an array of array to attach multiple files 
* @param bool $mode_smtp SMTP mode (deprecated) 
* @param string $template_path Template path 
* @param bool $die Die after error 
* @param string $bcc Bcc recipient 
* @return bool|int Whether sending was successful. If not at all, false, otherwise amount of recipients succeeded. 
*/ 
public static function Send($id_lang, $template, $subject, $template_vars, $to, 
    $to_name = null, $from = null, $from_name = null, $file_attachment = null, $mode_smtp = null, 
    $template_path = _PS_MAIL_DIR_, $die = false, $id_shop = null, $bcc = null, $reply_to = null) 

或者你可以去後臺和菜單Advanced Parameters -> Logs,鍵入消息過濾器:error和搜索結果。不能保證它只會顯示你的電子郵件錯誤,但它會縮小很多。

1

不可能告訴你Mail :: send()函數失敗的原因。可能有多種原因導致失敗。

有12行代碼在Mail :: send()函數中返回false,每個代碼都有不同的條件。您需要調試該函數才能找到確切的原因。

您可以在/classes/Mail.php

找到郵件發送::()函數Mail.php文件

提示:您可以添加日誌,每一個「返回false;」函數中的語句來檢查它們中的哪一個正在執行。