Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用带有codeigniter的HTML邮件模板_Php_Codeigniter - Fatal编程技术网

Php 使用带有codeigniter的HTML邮件模板

Php 使用带有codeigniter的HTML邮件模板,php,codeigniter,Php,Codeigniter,当用户注册到我的网站或在我的网站内执行某些活动时,我使用codeigniter电子邮件类发送电子邮件 问题是,有了下面这个简单的代码,我只能发送非常简单的HTML电子邮件。我还必须将整个HTML消息传递给函数。有没有什么方法可以让我将整个模板加载到函数本身中,并传递一条消息,就像我们在codeigniter with View中所做的那样,该消息将被放置在模板中 $message = 'Thank you for your order \n'; $message .= 'We will cont

当用户注册到我的网站或在我的网站内执行某些活动时,我使用codeigniter电子邮件类发送电子邮件

问题是,有了下面这个简单的代码,我只能发送非常简单的HTML电子邮件。我还必须将整个HTML消息传递给函数。有没有什么方法可以让我将整个模板加载到函数本身中,并传递一条消息,就像我们在codeigniter with View中所做的那样,该消息将被放置在模板中

$message = 'Thank you for your order \n';
$message .= 'We will contact you soon';
$this->email($message);

public function email($message = NULL){
    $this->load->library('email');

    $this->email->mailtype('html');
    $this->email->from('abbbba@gmail.com', 'Sohan Kc');
    $this->email->to('abbbbaa@gmail.com'); 

    $this->email->subject('Email Test');
    $this->email->message($message);    

    $this->email->send();
}

你为什么不照你说的做呢?:) 电子邮件类消息方法需要传递字符串。只需加载一个视图并将返回的字符串传递给该方法

public function email($message = NULL){
    $this->load->library('email');

    $mydata = array('message' => 'I am a message that will be passed to a view');
    $message = $this->load->view('my_email_template', $mydata, true);        

    $this->email->mailtype('html');
    $this->email->from('sohanmax2@gmail.com', 'Sohan Kc');
    $this->email->to('sohanmax02@gmail.com'); 

    $this->email->subject('Email Test');
    $this->email->message($message);    

    $this->email->send();
}

你为什么不照你说的做呢?:) 电子邮件类消息方法需要传递字符串。只需加载一个视图并将返回的字符串传递给该方法

public function email($message = NULL){
    $this->load->library('email');

    $mydata = array('message' => 'I am a message that will be passed to a view');
    $message = $this->load->view('my_email_template', $mydata, true);        

    $this->email->mailtype('html');
    $this->email->from('sohanmax2@gmail.com', 'Sohan Kc');
    $this->email->to('sohanmax02@gmail.com'); 

    $this->email->subject('Email Test');
    $this->email->message($message);    

    $this->email->send();
}

我发送电子邮件,但得到的html代码作为正文,我必须添加标题,以获得正确的内容,如下文所示,它将工作

$this->email->set_头('MIME-Version','1.0;charset=utf-8')


$this->email->set_头('Content-type','text/html')

我发送电子邮件,但得到了作为正文的html代码,我必须添加标题以获得正确的内容,如下面所示,它会成功的

$this->email->set_头('MIME-Version','1.0;charset=utf-8')


$this->email->set_头('Content-type','text/html')

我建议在邮件功能周围做一个包装,这样你就可以无问题地更新codeigniter邮件程序并保持最新。我建议在邮件功能周围做一个包装,这样你就可以无问题地更新codeigniter邮件程序并保持最新