Codeigniter无法连接到ssl://smtp.googlemail.com错误

时间:2017-05-22 14:54:12

标签: php codeigniter email ssl

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。

1 个答案:

答案 0 :(得分:0)

首先你应该检查电子邮件的任何配置是否都写在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' ;,