【问题标题】:Mail sent but not received, codeigniter邮件已发送但未收到,codeigniter
【发布时间】:2015-09-11 14:41:14
【问题描述】:

我已经配置了以下设置

 $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

返回路径:send-mail@gmail.com

回复:“send-mail@gmail.com”

X 发件人:send-mail@gmail.com

X-Mailer: CodeIgniter

X 优先级:3(正常)

消息 ID:

Mime 版本:1.0 内容类型:文本/纯文本;字符集=utf-8 内容传输编码:8bit

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

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

【问题讨论】:

  • 您使用什么类型的本地主机进行测试? xampp wamp 等
  • 另一件事是有时 codeigniter 不会发送,除非在 xampp 设置中配置了发送电子邮件设置youtube.com/watch?v=TO7MfDcM-Ho

标签: php codeigniter email smtp


【解决方案1】:

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

$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();

【讨论】:

  • 谢谢。它让我摆脱了上面提到的问题,但现在它显示了很多错误“fsockopen():无法连接”无法发送数据。 @Saty
  • 听起来不错,您解决了问题!!。现在您遇到了什么错误,请粘贴您的错误
  • fsockopen():SSL 操作失败,代码为 1。OpenSSL 错误消息:错误:140770FC:SSL 例程:SSL23_GET_SERVER_HELLO:未知协议 fsockopen():无法启用加密 fsockopen():无法连接到ssl://smtp.gmail.com:587 (未知错误) fwrite() 期望参数 1 是资源,布尔值给定此类错误@Saty
  • 代码$this->load->library('email'); 的小改动从这一行删除$config
  • 'smtp_port' => 465改成'smtp_port' => 587,然后检查
【解决方案2】:

别忘了先加载库

$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 发送邮件

阅读更多关于 CI 的电子邮件CI E-Mail Library

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-20
    • 1970-01-01
    • 2014-03-12
    相关资源
    最近更新 更多