已发送但未收到的邮件,codeigniter

时间:2015-06-25 06:27:07

标签: php codeigniter email smtp

我已配置以下设置

 $config = Array(

        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.gmail.com',
        'smtp_port' => 465,
        'smtp_user' => 'send-mail@gmail.com', // change it to yours
        'smtp_pass' => 'xyz', // change it to yours
        'smtp_timeout'=>20,
        'mailtype' => 'text',
        'charset' => 'iso-8859-1',
        'wordwrap' => TRUE
       );

$this->load->library('email',$config);
//$this->email->set_newline("\r\n");
$this->email->from('sender-mail@gmail.com', 'Garima');
$this->email->to('receiver-mail@gmail.com');

// mail message here

我收到以下消息:

  

您的邮件已使用以下协议成功发送:   邮件

     

来自:" Garima" send-mail@gmail.com

     

Return-Path:send-mail@gmail.com

     

回复:" send-mail@gmail.com"

     

X-Sender:send-mail@gmail.com

     

X-Mailer:CodeIgniter

     

X-Priority:3(正常)

     

消息ID:< @ gmail.com>

     

Mime-Version:1.0 Content-Type:text / plain;字符集= utf-8的   内容传输编码:8位

首先,如果我已将协议定义为smtp,为什么它将协议显示为邮件。

其次,没有" to"显示的消息中的字段。为什么会这样?我必须做出哪些改变?

2 个答案:

答案 0 :(得分:0)

您忘记在代码中初始化电子邮件配置设置

$this->email->initialize($config);

所以你的代码将是

 $this->load->library('email');
        $config = Array(
                'protocol' => 'smtp',
                'smtp_host' => 'ssl://smtp.gmail.com',
                'smtp_port' => 465,
                'smtp_user' => 'send-mail@gmail.com', // change it to yours
                'smtp_pass' => 'xyz', // change it to yours
                'smtp_timeout'=>20,
                'mailtype' => 'text',
                'charset' => 'iso-8859-1',
                'wordwrap' => TRUE
               );

         $this->email->initialize($config);// add this line

        //$this->email->set_newline("\r\n");
        $this->email->from('sender-mail@gmail.com', 'Garima');
        $this->email->to('receiver-mail@gmail.com');
        $this->email->subject('Email Test');
        $this->email->message('Testing the email class.');  
        $this->email->send();
        echo $this->email->print_debugger();

答案 1 :(得分:0)

不要忘记首先加载库

$this->load->library('email');

然后配置这些设置Can Refer here too

$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'xxx',//your E-mail
    'smtp_pass' => 'xxx',//Your password
    'mailtype'  => 'html', 
    'charset'   => 'iso-8859-1'
);

$this->load->library('email', $config);
$this->email->set_newline("\r\n");

// Set to, from, message, etc.
$this->email->from('your@example.com', 'Your Name');
$this->email->to('someone@example.com'); 
$this->email->cc('another@another-example.com'); 
$this->email->bcc('them@their-example.com'); 

$this->email->subject('Email Test');
$this->email->message('Testing the email class.');  

$result = $this->email->send();

使用 localhost

发送邮件
  1. 如果您使用 XAMPP ,请执行此设置Stack Answer for Send mail with XAMPP
  2. 如果您使用 wamp Stack Answer for Send mail with WAMP
  3. 发送邮件

    详细了解CI电子邮件CI E-Mail Library