2013-04-16 62 views
5

我在我的opencart中有一個腳本,由我自己製作,並且想讓它發送電子郵件,但我認爲當我嘗試獲取電子郵件參數時,它們會返回nullOpencart在自定義腳本中發送電子郵件

這裏是我的代碼:

$email_to = "[email protected]"; 
    $config = new Config(); 
    $mail = new Mail(); 


    $mail->protocol = $config->get('config_mail_protocol'); 
    $mail->parameter = $config->get('config_mail_parameter'); 
    $mail->hostname = $config->get('config_smtp_host'); 
    $mail->username = $config->get('config_smtp_username'); 
    $mail->password = $config->get('config_smtp_password'); 
    $mail->port = $config->get('config_smtp_port'); 
    $mail->timeout = $config->get('config_smtp_timeout');    
    $mail->setTo($email_to); 
    $mail->setFrom("[email protected][mydomain].com"); 
    $mail->setSender("[email protected][mydomain].com"); 
    $mail->setSubject("test send mail"); 
    $mail->setText("test message body text"); 
    $mail->send(); 

當我嘗試打電話:echo $config->get('config_mail_protocol');返回null

回答

5

不要創建的Config新的實例,但只是簡單地調用

$email_to = "[email protected]"; 
$mail = new Mail(); 

$mail->protocol = $this->config->get('config_mail_protocol'); 
$mail->parameter = $this->config->get('config_mail_parameter'); 
$mail->hostname = $this->config->get('config_smtp_host'); 
$mail->username = $this->config->get('config_smtp_username'); 
$mail->password = $this->config->get('config_smtp_password'); 
$mail->port = $this->config->get('config_smtp_port'); 
$mail->timeout = $this->config->get('config_smtp_timeout');    
$mail->setTo($email_to); 
$mail->setFrom("[email protected]"); 
$mail->setSender("[email protected]"); 
$mail->setSubject("test send mail"); 
$mail->setText("test message body text"); 

$mail->send(); 
+0

魔獸,這只是救了我的一天先生:D在這裏,有我的有用和問題解決:D – nunong21

+0

很高興幫助! :-) – shadyyx

+0

順便說一下,是否可以調用$ mail和我在自定義類中創建的配置? – nunong21

4

我所面臨的問題與前面提到的代碼發送郵件。因爲Opencart的2

Opencart的郵件變量已更改這是Opencart的2.3

$mail = new Mail(); 
$mail->protocol = $this->config->get('config_mail_protocol'); 
$mail->parameter = $this->config->get('config_mail_parameter'); 
$mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname'); 
$mail->smtp_username = $this->config->get('config_mail_smtp_username'); 
$mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'); 
$mail->smtp_port = $this->config->get('config_mail_smtp_port'); 
$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout'); 

$mail->setTo($order_info['email']); 
$mail->setFrom($this->config->get('config_email')); 
$mail->setSender(html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8')); 
$mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8')); 
$mail->setHtml($this->load->view('mail/order', $data)); 
$mail->setText($text); 
$mail->send(); 

代碼塊從catalog/model/checkout/order.php

直抄我希望有人會覺得這有用的代碼。

相關問題