2014-04-22 31 views
2

作爲一個擴展的版本這個問題:PHPMailer(): Called Mail() without being connected在wordpress中是否有更清晰的PHPmailer代碼..?

我們不能使用的PHPMailer的所有配置在一個數組,有些事情是這樣的:

$mail = array(
     'SMTPAuth' => true, 
     'Host'  => 'smtp.millicenthotel.com', 
     'Port'  => 25, 
     'Username' => '[email protected]', 
     'Password' => 'gboskeritysoldier1' 
     ); 

我想是這樣的,它不工作。我正在尋找更乾淨的方式來做到這一點。

在此先感謝。

+0

我敢肯定,你可以編輯構造函數接受一個配置/選項陣列。 –

+0

@PatrickQ - 事實上,你可以 - 但直接配置它使用動作鉤。見答案 –

回答

2

你有一個動作鉤叫phpmailer_init

法典:

的wp_mail功能依靠的PHPMailer類通過PHP的郵件功能來發送電子郵件 。 phpmailer_init動作鉤子允許你將 掛鉤到phpmailer對象並傳入你自己的參數。

例子(codex again):

add_action('phpmailer_init', 'my_phpmailer_example'); 

function my_phpmailer_example($phpmailer) { 
    $phpmailer->IsSMTP();  //switch to smtp 
    $phpmailer->Host = 'smtp.example.com'; 
    $phpmailer->Port = 25; 
    $phpmailer->Username = 'yourusername'; 
    $phpmailer->Password = 'yourpassword'; 
} 
+0

非常感謝它的工作 –

+0

因此,如果它爲你工作,你可能想[接受](http://stackoverflow.com/help/某人回答)答案,通過點擊投票下的小V字母來標記問題爲答案。 –

+0

完成..!我只是新來的堆棧家庭 –

相關問題