3

codeignitorメールクラスを使用して、htmlビューではなくhtmlコードを表示するメールを使用して、codeignitorで添付ファイル付きのhtmlメールを送信する際に問題があります。

以下の構成でメールタイプをhtmlとして設定したのは私のコードです

$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("\r\n");

       $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";

        }
4

2 に答える 2

5

このように構成します

$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("\r\n");
$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();
于 2016-08-03T09:57:27.210 に答える
0

[すべての人に申し訳ありません。明確にするためにコメントするのに十分な担当者がいません]

私はあなたの正確なコード(添付ビットを除く)を試してみましたが、HTMLメールをGmailアカウントに送信するのに問題なく動作しました。以下に私の完全なワーキングクラスを提供します:

class rohithipix extends CI_Controller {

    public function html_email() {

        $message = "<h1>start</h1><p>test</p>";
        $mail_to = "test@gmail.com";
        $from_mail = 'test2@gmail.com';
        $from_name = 'dave';
        $reply_to = 'test2@gmail.com';
        $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("\r\n");

        $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";
        }
    }

}

テスト中にこれらを送信しようとしている電子メールクライアントは何ですか?

于 2013-01-17T17:28:44.153 に答える