用 CodeIgniter 寄信
果然也是有人寫好啦,首先把這包 codeigniter-phpmailer 打包回去,然後依據裡面的東西分別放到對應的資料夾。
之後把 application/config/email.php 裡的設定改一下
$config['smtp_host'] = 'smtp.gmail.com'; //如果是 gmail 就改這樣
$config['smtp_user'] = '[email protected]'; //你收發的 email
$config['smtp_pass'] = 'yourpassword'; //email 的密碼
$config['smtp_port'] = 465; //這是 gmail 的 port
然後再照他的範例,在要寄信的地方把下面的地方改一下就好了。
之後把 application/config/email.php 裡的設定改一下
$config['smtp_host'] = 'smtp.gmail.com'; //如果是 gmail 就改這樣
$config['smtp_user'] = '[email protected]'; //你收發的 email
$config['smtp_pass'] = 'yourpassword'; //email 的密碼
$config['smtp_port'] = 465; //這是 gmail 的 port
然後再照他的範例,在要寄信的地方把下面的地方改一下就好了。
- $this->load->library('email');
- $subject = 'This is a test';
- $message = '<p>This message has been sent for testing purposes.</p>';
- // Get full html:
- $body =
- '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset='.strtolower(config_item('charset')).'" />
- <title>'.html_escape($subject).'</title>
- <style type="text/css">
- body {
- font-family: Arial, Verdana, Helvetica, sans-serif;
- font-size: 16px;
- }
- </style>
- </head>
- <body>
- '.$message.'
- </body>
- </html>';
- // Also, for getting full html you may use the following internal method:
- //$body = $this->email->full_html($subject, $message);
- $result = $this->email
- ->from('[email protected]')
- ->reply_to('[email protected]') // Optional, an account where a human being reads.
- ->to('[email protected]')
- ->subject($subject)
- ->message($body)
- ->send();
留言