php - SMTP 错误:220 smtpauth.net4india.com ready 无法使用 PHP SMTP 发送电子邮件。您的服务器可能未配置
问题描述
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 记录。将路由更改为远程管理器。
我做了很多谷歌搜索仍然没有解决方案。
解决方案
经过大量研发后,我最终发现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,并使用那里的服务器发送邮件。
当我将身份验证设置为假时,我什至删除了我的用户名和密码。
如godaddy所述,将端口号更改为25。
推荐阅读
- mysql - 选择值为空或零的列
- java - javax.persistence、javax.persistence-api和javaee-api的区别
- c# - 如何创建更大的复选框
- protractor - allure.createAttachment 异常错误 - 无法读取未定义的属性“currentStep”
- python-3.x - 数据是否欠拟合?
- android-studio - 使用搜索栏时,Android Studio 有一个非常错误的属性窗口
- sql - 使用组合框中的信息更新记录时的语法问题
- javascript - 负数的阶乘超过最大调用堆栈大小
- php - How do I assign an object child value to a variable?
- c++ - 为什么“l”的值变成了4?