【问题标题】:Codeigniter unable to connect to ssl://smtp.googlemail.com errorCodeigniter 无法连接到 ssl://smtp.googlemail.com 错误
【发布时间】:2017-10-22 07:14:27
【问题描述】:

PHP:

$config = Array(
  'useragent' => 'CodeIgniter',
  'mailpath' => '/usr/bin/sendmail',
  'protocol' => 'smtp',
  'smtp_host' => 'mail.kakaproperty.com',
  'smtp_port' => 587,
  'smtp_user' => 'info@kakaproperty.com', 
  'smtp_pass' => '******', 
  'mailtype' => 'html',
  'charset' => 'iso-8859-1',
  'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->set_mailtype("html");
$this->email->from('info@kakaproperty.com'); // change it to yours
$this->email->to($data['email']);// change it to yours
$this->email->subject('Welcome to kaka property');
$this->email->message("New message by kaka property");
if($this->email->send())
{
    echo 1;
}
else
{
    $this->email->print_debugger();
}

任何人都可以请帮助我为什么它显示错误无法连接 ssl://smtp.googlemail.com 我使用 kakaproperty.com 作为主机为什么会发生这种情况。我从配置文件夹中删除了 email.php。

【问题讨论】:

  • 划掉我之前的评论,不要使用465作为端口
  • @AntonisTsimourtos 我试过 465 但它不起作用。
  • 您确定凭据正确吗?我不知道stmp_user 是否正确..
  • @AntonisTsimourtos 先生,所有信息都是正确的。

标签: php codeigniter email ssl


【解决方案1】:

首先,您应该检查电子邮件的任何配置是否作为外部文件写入 codeigniter。如果是,请检查配置,否则请参见下文。

当托管服务器和电子邮件服务器相同时,有时您不想在 Codeigniter 代码中手动编写服务器配置。您可以按照以下方式直接发送电子邮件

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

$config['mailtype'] = 'html';
$config'charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;

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

$this->email->from('xx@xx.xx', 'xxx');
$this->email->to('yy@yy.yy');
$this->email->subject('xxxxx');
$this->email->message('xxx xxx xxx  xxx');

if ( ! $this->email->send()) 
       echo "Error";
} else {
    echo "Done";
}

否则,如果您使用的是 ssl://smtp.gmail.com。您可以使用以下代码

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

$config['protocol']    = 'smtp';
$config['smtp_host']    = 'ssl://smtp.gmail.com';
$config['smtp_port']    = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user']    = 'xx@xx.xx';
$config['smtp_pass']    = '*****';

$this->email->initialize($config);
$this->email->from('xx@xx.xx', 'xxx');
$this->email->to('yy@yy.yy');
$this->email->subject('xxxxx');
$this->email->message('xxx xxx xxx  xxx');

if ( ! $this->email->send()) {
   echo "Error";
} else {
   echo "Done";
}

如果您收到 fsockopen() 错误,请尝试使用 'smtp_host' => 'ssl://smtp.googlemail.com',

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-08
    • 2019-03-11
    • 2017-04-11
    • 2019-11-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多