Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
520 views
in Technique[技术] by (71.8m points)

codeigniter - Email showing html source when i send email using codignator email class

I have a problem in sending html mail with attachment in codeignitor using codeignitor email class the mail showing html code instead of html view.

i had set the mailtype as html in config below is my code

$message="<p>test</p>";
$mail_to = "email@gmail.com";
$from_mail = $useremail;
$from_name = $userfname;
$reply_to = $useremail;
$subject = "Abstract Details";



$file_name = $datamail['varafile'];
$path = realpath('uploads/abstract');

// Read the file content
$file = $path.'/'.$file_name;

$config = array (
              'protocol' =>'sendmail',
                          'mailtype' => 'html',
                          'charset'  => 'utf-8',
                          'priority' => '1'
                               );
       $this->load->library('email',$config);


      $this->email->set_newline("
");

       $this->email->from($from_mail,$from_name);
        $this->email->to($mail_to);    
        $this->email->subject($subject);      
        $this->email->message($message);
        $this->email->attach($file);
        if($this->email->send()){
        echo "Mail send successfully";

        }else{
         echo "Error in sending mail";

        }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

configure it like this way

$config = Array(
    'protocol' => 'sendmail',
    'mailtype' => 'html',
    'smtp_host' => '', //your SMTP host
    'smtp_port' => 26,
    'smtp_user' => '', //your SMTP email address
    'smtp_pass' => '', //your SMTP email password
    'charset' => 'iso-8859-1',
    'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("
");
$this->email->set_header('MIME-Version', '1.0; charset=utf-8'); //must add this line
$this->email->set_header('Content-type', 'text/html'); //must add this line

$this->email->from('', ''); //from/sender email [with name (optional)]
$this->email->to(); //to/receiver email

$this->email->subject(''); //email subject
$message = $this->load->view('...directory.../...filename...',$data,TRUE); //html template/body with dynamic data
$this->email->message($message);
$this->email->send();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...