简体   繁体   English

mediatemple - 无法使用codeigniter发送电子邮件

[英]mediatemple - can't send email using codeigniter

I can't send emails using mediatemple in codeigniter.I've checked the email password and smtp host and they are correct. 我无法在codeigniter中使用mediatemple发送电子邮件。我已经检查了电子邮件密码和smtp主机,它们是正确的。

This is the error: 这是错误:

Severity: Notice

Message: fwrite() [function.fwrite]: send of 12 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host.

Filename: libraries/Email.php

Line Number: 1846

This is my code: I have replaced sxxxxx.gridserver.com with my correct smtp. 这是我的代码:我用正确的smtp替换了sxxxxx.gridserver.com。

function _sendEmail($from,$fromname,$to,$subject,$message){
            $config = array(
            'protocol' => 'smtp',
            'smtp_host' => 'sxxxxx.gridserver.com',
            'smtp_port' => 465,
            'smtp_user' => 'noreply@mywebsite.com',
            'smtp_pass' => 'mypass'
        );


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

        $this->email->from($from,$fromname);
        $this->email->to($to);
        $this->email->subject($subject);
        $this->email->message($message);
        $this->email->send();
    }

Any help would be appreciated. 任何帮助,将不胜感激。

Edit : I have fixed this problem using port 25. 编辑:我已使用端口25修复此问题。

'smtp_crypto'   => 'ssl',

将其添加到您的配置中

You need to initialise the the config, see the codeigniter documentation for the email class . 您需要初始化配置,请参阅电子邮件类的codeigniter文档

Here is my example which works well... 这是我的例子,效果很好......

    function send_email($attributes) {

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

        $this->email->set_newline("\r\n");

        $config['protocol'] = 'smtp';
        $config['smtp_host'] = 'host';
        $config['smtp_port'] = '465';
        $config['smtp_user'] = 'user@smtp.com';
        $config['smtp_from_name'] = 'FROM NAME';
        $config['smtp_pass'] = 'XXX';
        $config['wordwrap'] = TRUE;
        $config['newline'] = "\r\n";
        $config['mailtype'] = 'html';                       

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

        $this->email->from($config['smtp_user'], $config['smtp_from_name']);
        $this->email->to($attributes['to']);
        $this->email->cc($attributes['cc']);
        $this->email->bcc($attributes['cc']);
        $this->email->subject($attributes['subject']);

        $this->email->message($attributes['message']);

        if($this->email->send()) {
            return true;        
        } else {
            return false;
        }       

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM