【问题标题】:SMTP error: 220 smtpauth.net4india.com ready Unable to send email using PHP SMTP. Your server might not be configuredSMTP 错误:220 smtpauth.net4india.com ready 无法使用 PHP SMTP 发送电子邮件。您的服务器可能未配置
【发布时间】:2019-06-27 07:17:40
【问题描述】:
public function send_mail()
{
    $this->CI->load->library('email');
    $config = array(
        'protocol'  => 'smtp',
        'smtp_host' => 'smtpauth.net4india.com',
        'smtp_port' => 587,
        'smtp_user' => 'xxxxx@my_domain.in',
        'smtp_pass' => 'xxxxxxxx',
        'newline'   => '\r\n',
        'mailtype'  => 'html',
        'charset'   => 'utf-8'
    );
    $this->CI->email->initialize($config);
    $this->CI->email->set_mailtype("html");
    $this->CI->email->set_newline("\r\n");
    $this->CI->email->from('info@my_domain.in', 'My Domain');
    $this->CI->email->to('xxxx@gmail.com');
    $this->CI->email->subject("Test Subject");
    $this->CI->email->message('Test Content');
    if(!$this->CI->email->send())
    {
        $error = $this->CI->email->print_debugger();
        echo "<pre>"; print_r($error); echo "</pre>"; exit;
        return false;
    }
    return true;
}

我在 net4india.com 上注册了我的域和电子邮件,并在 godaddy 托管。

使用上面的代码,我可以从本地主机发送邮件,但不能从 Godaddy 服务器发送邮件。

我在 godaddy 托管中添加了 mx 记录。 将路由更改为远程管理器。

我做了很多谷歌搜索仍然没有解决方案。

【问题讨论】:

标签: php codeigniter smtp


【解决方案1】:

经过大量研发后,我最终找到了Sending mail through other providers isn't allowed on godaddy

public function send_mail()
{
    $this->CI->load->library('email');
    $config = array(
            'protocol'  => 'mail',
            '_smtp_auth' => FALSE,
            'smtp_host' => 'localhost',
            'smtp_port' => 25,
            'newline'   => '\r\n',
            'mailtype'  => 'html',
            'charset'   => 'utf-8'
        );
     $this->CI->email->initialize($config);
    $this->CI->email->set_mailtype("html");
    $this->CI->email->set_newline("\r\n");
    $this->CI->email->from('info@my_domain.in', 'My Domain');
    $this->CI->email->to('xxxx@gmail.com');
    $this->CI->email->subject("Test Subject");
    $this->CI->email->message('Test Content');
    if(!$this->CI->email->send())
    {
        $error = $this->CI->email->print_debugger();
        echo "<pre>"; print_r($error); echo "</pre>"; exit;
        return false;
    }
    return true;
}

旧配置:

$config = array(
        'protocol'  => 'smtp',
        'smtp_host' => 'smtpauth.net4india.com',
        'smtp_port' => 587,
        'smtp_user' => 'xxxxx@my_domain.in',
        'smtp_pass' => 'xxxxxxxx',
        'newline'   => '\r\n',
        'mailtype'  => 'html',
        'charset'   => 'utf-8'
    );

新配置:

$config = array(
            'protocol'  => 'mail',
            '_smtp_auth' => FALSE,
            'smtp_host' => 'localhost',
            'smtp_port' => 25,
            'newline'   => '\r\n',
            'mailtype'  => 'html',
            'charset'   => 'utf-8'
        );

我最终将 _smtp_Auth 设置为 false,并使用那里的服务器发送邮件。

我什至删除了我的用户名和密码,因为我将身份验证设置为 false。

将端口号更改为 Godaddy 提到的 25。

【讨论】:

    【解决方案2】:

    这个适用于 Codeigniter 3.x 的工作解决方案

    在 config 文件夹中创建 email.php 文件,这将自动加载电子邮件配置

    <?php
    defined('BASEPATH') OR exit('No direct script access allowed');
    
    $config['useragent'] = 'Codeigniter';
    $config['protocol'] = 'smtp';
    $config['smtp_host'] = 'ssl://mail.domain.com';
    $config['smtp_port'] = '465';
    $config['smtp_timeout'] = '7';
    $config['smtp_user'] = 'noreply@domain.com';
    $config['smtp_pass'] = 'Password@123';
    $config['charset'] = 'utf-8';
    $config['newline'] = '\r\n';
    $config['mailtype'] = 'html';
    $config['validation'] = TRUE; 
    

    在你的控制器中使用

    $html = '<p>Hello</p>';
    $html .= '<p>This is some demo email text.</p>';
    
                    $this->load->library('email');
                    $this->email->from('noreply@example.com', 'Label', 'returnpath@example.com');
                    $this->email->to('recipient@example.com');
                    $this->email->bcc('cc@example,com', 'anothercc@example.com');
                    $this->email->subject('Subject For Mail');    
                    $this->email->message($html);
                    $this->email->send();
    

    【讨论】:

      猜你喜欢
      • 2018-11-29
      • 2017-12-28
      • 2019-02-23
      • 2022-01-05
      • 2018-06-07
      • 2017-04-27
      • 1970-01-01
      • 2021-10-01
      相关资源
      最近更新 更多