I know - there are already discussions concerning this, but they all didn't help.
All I want is to send a simple html mail - with:
$this->load->library('email');
$this->email->from('me@myadress.de', 'My name');
$this->email->to('me@home.de');
$this->email->subject('Email Test');
$this->email->message('test'); # for test only - normally I load a html view
$this->email->send();
Works fine with the default configuration ( $config['mailtype'] = 'text';
), but when I change it to $config['mailtype'] = 'html';
- I just get
Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.
The only answers I found was to use SMPT - but I would prefer a solution using sendmail. (I'm pretty sure sendmails supports html mails. ^^)
Any other hints? I've no idea how to debug this... the email-print looks ok to me.
If you want to send an html as a email, please check the below controller file
class Mail extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
}
public function index()
{
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'tls://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'xxx@gmail.com',
'smtp_pass' => '*********',
'mailtype' => 'html',
'charset' => 'utf-8'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('xxx@gmail.com');
$this->email->to("yyyy@gmail.com");
$this->email->subject('Test Email');
$body = $this->load->view('welcome_message',null,TRUE);
$this->email->message($body);
if (!$this->email->send()){
echo 'fail to load email';
}
else {
echo 'success to send email';
}
}
}
Where welcome_message
is the html view file which you want to send as a mail body
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.