发送个性化的邮件

时间:2019-07-08 15:17:47

标签: codeigniter

使用codeigniter,我发送带有个性化正文的邮件。 好吧,除了我无法从控制器代码中检索($ name)和($ message)。当我收到电子邮件而不是Welcome Luigi时,我收到Welcome $ name ....并作为消息-> $ message

控制器:

class Welcome extends CI_Controller {

function __construct(){

    parent::__construct();

    $this->load->config('emailer');
    $this->load->library(array('form_validation', 'Mymailer', 'upload', 'email'));
    $this->load->helper(array('form', 'url', 'file'));

public function index()
{
      if ($this->form_validation->run() == TRUE){
        $name = $this->input->post('name', TRUE);
        $email = $this->input->post('email', TRUE); 
        $subject = $this->input->post('subject', TRUE); 
        $message = $this->input->post('message', TRUE); 
        $file = $this->input->post('file', TRUE);
        $path = APPPATH.'/tmp/';    
        $xmsg = $this->load->view('email_body','',TRUE);

        $this->mymailer->addAddress($email, $name);
        $this->mymailer->Subject=($subject);
        $this->mymailer->msgHTML($xmsg);

文件application / views / email_body.php

        <td class="h2" style="padding: 5px 0 0 0;" align="center">Welcome ' . $name . '</td>

    <div style="font-family: Arial, Helvetica, sans-serif; color: #666; font-size: 14px;"></div>' . $message . '<br /><br />

请问当电子邮件出现时我该怎么办?

1 个答案:

答案 0 :(得分:0)

您应该将名称和消息数据传递给

$data["name"] =  $name;
$data["message"] =  $message;
$xmsg = $this->load->view('email_body',$data,TRUE);

然后只有数据将被替换在email_body.php