email
views/mail/user_mail.php
メール本文
libraries/MY_Email.php
<?php
class My_Email extends CI_Email {
public function __construct(array $config = array())
{
parent::__construct($config);
}
/**
* get Body by tempalte
*
* @param string
* @param array
* @return string
*/
public function get_template_contents($template, $values = array())
{
$file = VIEWPATH . $template;
if(!file_exists($file)){
$file .= '.php';
}
extract($values);
ob_start();
include($file);
$contents = ob_get_contents();
ob_end_clean();
return $contents;
}
}
config/config_mail.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$config['user_mail'] = array(
'from' => 'from@sample.co.jp',
'from_name' => 'fromName',
'subject' => 'メールタイトル',
);
controller
$this->load->library('email');
$config_key = 'user_mail';
$this->load->config('config_mail');
$user_mail = $this->config->item($config_key);
$mail = new PHPMailer();
$mail->CharSet = "iso-2022-jp";
$mail->Encoding = "7bit";
$mail->AddAddress('to@sample.co.jp');
$mail->From = $user_mail['from'];
$mail->FromName = mb_encode_mimeheader(mb_convert_encoding($user_mail['from_name'], "JIS", "UTF-8"));
$mail->Subject = mb_encode_mimeheader(mb_convert_encoding($user_mail['subject'], "JIS", "UTF-8"));
$body = $this->email->get_template_contents('mail/'.$config_key);
//$mail->Body = mb_convert_encoding($body, "JIS", "UTF-8");
$mail->Body = mb_convert_encoding($body,"ISO-2022-JP-ms","UTF-8");//機種依存文字が含まれるならこちら
$result = $mail->Send();