簡體   English   中英

如何使用codeigniter中的View發送包含內容的電子郵件

[英]How to send an email with content from a View in codeigniter

我想從我的應用程序向用戶發送一封電子郵件,其中包含從視圖中加載的電子郵件的內容。 這是我到目前為止嘗試過的代碼:

$toemail = "user@email.id";

$subject = "Mail Subject is here";
$mesg = $this->load->view('template/email');

$this->load->library('email');

$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';

$this->email->initialize($config);

$this->email->to($toemail);
$this->email->from($fromemail, "Title");
$this->email->subject($subject);
$this->email->message($mesg);
$mail = $this->email->send();
  1. 需要調用$this->load->library('email'); 在控制器內以及CI中的電子郵件工作。
  2. 此外,在您的代碼中: $fromemail未初始化。
  3. 您需要在服務器上具有SMTP支持
  4. 分配值和鍵之前,應將$ config聲明為數組。

工作守則:

$this->load->library('email');
$fromemail="ad@c.com";
$toemail = "user@email.id";
$subject = "Mail Subject is here";
$data=array();
// $mesg = $this->load->view('template/email',$data,true);
// or
$mesg = $this->load->view('template/email','',true);


$config=array(
'charset'=>'utf-8',
'wordwrap'=> TRUE,
'mailtype' => 'html'
);

$this->email->initialize($config);

$this->email->to($toemail);
$this->email->from($fromemail, "Title");
$this->email->subject($subject);
$this->email->message($mesg);
$mail = $this->email->send();

編輯: $mesg = $this->load->view('template/email',true); 如lycanian所指出的應該是真實的 通過將其設置為true,它不會將數據發送到輸出流,但會以字符串形式返回。

編輯: $this->load->view(); 需要第二個帶數據的參數或者像$mesg = $this->load->view(view,data,true); 如果不是它不會工作

這行$ mesg = $ this-> load-> view('template / email',true); 應該是這樣的
$ mesg = $ this-> load-> view('template / email','',true);
在值為true之前使用單引號,它將完美地工作

電子郵件模板發送在codeigniter中,我們需要在發送電子郵件之前放置和元標記

$this->data['data'] = $data;
$message = $this->load->view('emailer/create-account', $this->data,  TRUE);
$this->email->set_header('MIME-Version', '1.0; charset=utf-8');
$this->email->set_header('Content-type', 'text/html');
$this->email->from($email, $name);
$this->email->to('emailaddres@mail.com');
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();

你會試試!! 面對許多錯誤后,它正在為我的工作

            $subject = 'New message.';
            $config = Array(        
                'protocol' => 'sendmail',
                'smtp_host' => 'Your smtp host',
                'smtp_port' => 465,
                'smtp_user' => 'webmail',
                'smtp_pass' => 'webmail pass',
                'smtp_timeout' => '4',
                'mailtype'  => 'html', 
                'charset'   => 'utf-8',
                'wordwrap' => TRUE
            );
            $this->load->library('email', $config);
            $this->email->set_newline("\r\n");
            $this->email->set_header('MIME-Version', '1.0; charset=utf-8');
            $this->email->set_header('Content-type', 'text/html');

            $this->email->from('from mail address', 'Company name ');
            $data = array(
                 'message'=> $this->input->post('message')
                     );
            $this->email->to($toEmail);  
            $this->email->subject($subject); 

            $body = $this->load->view('email/sendmail.php',$data,TRUE);
            $this->email->message($body);   
            $this->email->send();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM