【问题标题】:Codeigniter send mail working in localhost but not in serverCodeigniter 发送邮件在 localhost 但不在服务器中
【发布时间】:2019-03-28 15:29:27
【问题描述】:

我正在尝试什么

我正在构建一个 codeigniter 应用程序并且需要发送邮件。当我尝试从 localhost 发送邮件时,我的邮件配置运行良好。但是在服务器上托管时它不起作用。

邮件配置

var $useragent      = "CodeIgniter";
var $mailpath       = "/usr/sbin/sendmail"; // Sendmail path
var $protocol       = "smtp";   // mail/sendmail/smtp
var $smtp_host      = "send.one.com";       // SMTP Server.  Example: mail.earthlink.net
var $smtp_user      = "no-reply@domain.com";        // SMTP Username
var $smtp_pass      = "pass";       // SMTP Password
var $smtp_port      = "25";     // SMTP Port
var $smtp_timeout   = 60;       // SMTP Timeout in seconds
var $smtp_crypto    = "";       // SMTP Encryption. Can be null, tls or ssl.
var $wordwrap       = TRUE;     // TRUE/FALSE  Turns word-wrap on/off
var $wrapchars      = "76";     // Number of characters to wrap at.
var $mailtype       = "html";   // text/html  Defines email formatting
var $charset        = "utf-8";  // Default char set: iso-8859-1 or us-ascii
var $multipart      = "mixed";  // "mixed" (in the body) or "related" (separate)
var    $alt_message         = '';       // Alternative message for HTML emails
var $validate       = FALSE;    // TRUE/FALSE.  Enables email validation
var $priority       = "1";      // Default priority (1 - 5)
var $newline        = "\r\n";       // Default newline. "\r\n" or "\n" (Use "\r\n" to comply with RFC 822)
var $crlf           = "\r\n";

从服务器发送时出现以下错误

 A PHP Error was encountered

 Severity: Warning

 Message: fsockopen(): unable to connect to send.one.com:25 (Connection timed out)

 Filename: libraries/Email.php

 Line Number: 1689

应用程序托管在 one.com 上

【问题讨论】:

    标签: codeigniter email


    【解决方案1】:

    我遇到了同样的问题。在尝试了几次但未能找到解决方案后,我将协议更改为 ma​​il。如果您正在更改电子邮件协议,您可能会收到以下错误:

    A PHP Error was encountered
    Severity: Warning
    Message: mail(): Policy restriction in effect. The fifth parameter is disabled on this system
    Filename: libraries/Email.php
    Line Number: 1537
    

    只需在函数 _send_with_mail() 中更改 /system/libraries/email.php 中的代码

    来自

    if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From']))) 
    

    if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str)) 
    

    因为:“// 大多数使用“-f”标志的 sendmail 文档后面都缺少空格,但是 // 我们遇到了似乎需要它的服务器。”

    希望有人可以提供使用 smtp 发送邮件的解决方案。

    【讨论】:

      【解决方案2】:

      我也在寻找解决方案,大多数时候在 localhost 上一切都很好,但在服务器上一切都很糟糕。但是经过多次尝试后,我根据不同的服务器(例如 Godaddy、Plesk、Hostinger 等)理解了一件事情...... 这是一个协议和端口号的游戏 -

      var $protocol  = "smtp";
      var $protocol  = "tls";
      var $protocol  = "imps";
      var $protocol  = "mail";
      var $protocol  = "sendmail";
      

      端口相同 -

      var $smtp_port = "25"; //It works most of time on localhost
      var $smtp_port = "465"; //For gmail
      var $smtp_port = "587"; // Sometime work for gmail and for others
      var $smtp_port = "995"; // On few cases
      

      还有一些smtp用户的情况

      var $smtp_user  = "ssl://smtp.gmail.com";
      var $smtp_user  = "ssl://smtp.googlemail.com";
      var $smtp_user  = "tls://smtp.yourmail.com";
      var $smtp_user  = "imps://smtp.yourmail.com";
      var $smtp_user  = "smtp.gmail.com";
      var $smtp_user  = "smtp.googlemail.com";
      

      但大多数服务器不允许 ssl:// 或他们直接想要电子邮件地址的所有其他前缀。 是的,这是令人困惑的,但在服务器上配置电子邮件是正确的,这对于第一次使用服务器的用户来说就像里程碑,但之后你知道服务器上的事情是如何发生的,你会很容易找到你的解决方案。 但祝你好运。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-02-15
        • 2017-02-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多