我想從codeigniter發送電子郵件,通過從數據庫和消息以html格式從數據庫中獲取某些數據(如名稱)來獲取收件人。這是我的控制器代碼。在codeigniter中發送電子郵件格式html
function send_email(){
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '[email protected]',
'smtp_pass' => '2341',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$message = '
<html>
<head>
<title>Packet</title>
</head>
<body>
<p>you have book this</p>
<table>
<tr>
<td>ID Booking</td>
<td>'.$id_booking.'</td>
</tr>
<tr>
<td>Price</td>
<td>'.$price'</td>
</tr>
<tr>
<td>Name</td>
<td>'.$name.'</td>
</tr>
</table>
</body>
</html>
';
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->set_mailtype("html");
$this->email->from('[email protected]', 'Shin');
$this->email->to($user);
$this->email->subject($subject);
$this->email->message($message);
if($this->email->send())
{
echo 'Email sent.';
}
else
{
show_error($this->email->print_debugger());
}
}
我的數據庫包含id_booking,價格,名稱,電子郵件的預訂表。 所以問題是我不知道如何從數據庫中獲取用戶電子郵件,並獲得$ id_booking,$ price和$ name?對不起,我是學習編程的新手..
我希望這不是你真正的用戶名和密碼。 – 2014-11-06 18:40:34
通常您會在模型中創建函數來獲取行,然後您可以從控制器調用該函數。 – 2014-11-06 18:41:47