【问题标题】:mediatemple - can't send email using codeignitermediatemple - 无法使用 codeigniter 发送电子邮件
【发布时间】:2012-05-30 04:56:08
【问题描述】:

我无法在 codeigniter 中使用 mediatemple 发送电子邮件。我检查了电子邮件密码和 smtp 主机,它们是正确的。

这是错误:

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

这是我的代码: 我已将 sxxxxx.gridserver.com 替换为正确的 smtp。

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

任何帮助将不胜感激。

编辑:我已经使用端口 25 解决了这个问题。

【问题讨论】:

  • 如果您通过 SSL 连接并且它拒绝连接,则您的服务器上可能没有正确安装/启用/配置 SSL。你的phpinfo() 是什么样的?
  • 你可能在本地机器上使用它

标签: php email codeigniter smtp


【解决方案1】:
'smtp_crypto'   => 'ssl',

将此添加到您的配置中

【讨论】:

    【解决方案2】:

    你需要初始化配置,见the codeigniter documentation for the email class

    这是我的例子,效果很好......

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

    【讨论】:

    • 我的代码适用于 gmail 但不适用于 mediatemple。它与 mediatemple 有关。我也尝试过你的代码,但遇到了同样的错误。
    • 我想你需要联系Mediatemplate来解决这个错误,似乎smtp主机有问题。也许有一些安全功能可以阻止您发送邮件。
    • 修复了问题。端口 456 仅用于 ssl。我需要使用 25。无论如何感谢您的帮助。
    猜你喜欢
    • 2013-06-15
    • 2012-10-31
    • 2012-12-05
    • 1970-01-01
    • 2015-09-06
    相关资源
    最近更新 更多