[英]Sending smtp mail without smtp server installed locally
我是否可以使用CodeIgniter在本地開發PC上發送SMTP電子郵件,而無需在本地開發PC上安裝SMTP服務器應用程序?
例如,以下操作無效。
application / config / email.php
$config['mailtype'] = 'html';
$config['protocol'] = 'smtp';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = 'my_gmail_account@gmail.com';
$config['smtp_pass'] = '*********';
控制器代碼
$this->load->library('email');
$this->email->from('my_gmail_account@gmail.com', 'Noel');
$this->email->to('my_gmail_account@gmail.com');
$this->email->subject('SMTP email Test');
$this->email->message('Testing smtp email in codeigniter.');
$this->email->send();
$data['message'] = "Sorry Unable to send email...";
if($this->email->send()){
$data['message'] = "Mail sent...";
}
$this->load->view('test_view', $data);
以下返回
抱歉,無法發送電子郵件...
並且沒有到達目標電子郵件。
嘗試將參數加載到數組中,然后使用數組源代碼初始化庫:CodeIgniter Forum :
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxx',
'smtp_pass' => 'xxx',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
// Set to, from, message, etc.
$result = $this->email->send();
另外,也許您需要在php.ini
啟用SSL。 如果看到以下行:
;extension=php_openssl.dll
通過從行首刪除分號來取消注釋,然后重新啟動PHP。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.