Codeigniter无法发送电子邮件,托管时有一些错误

My project is work fine in localhost of my pc, but hosted it on the server there are some errors.

This is my function in codeigniter:

 function sendMail_confirm_register(){

  $config = Array(
      'protocol' => 'smtp',
      'smtp_host' => 'ssl://smtp.googlemail.com',
      'smtp_port' => 465,
      'smtp_user' => 'myemail@gmail.com', 
      'smtp_pass' => 'mypassword',
      'mailtype' => 'html',
      'charset' => 'iso-8859-1',
      'wordwrap' => TRUE
  );


  $this->load->library('email', $config);
  $this->email->set_newline("
");
  $this->email->from('myemail@gmail.com','mydomain.com');
  $this->email->to('someone@gmail.com');
  $this->email->subject('Complete your registration!');
  $this->email->message('Test Message');
    if($this->email->send())
    {
       echo "The email has been sent!";
    }
    else
    {
       echo "Cannot send email!";
    }


}

This is error as below:

A PHP Error was encountered

Severity: Warning

Message: fsockopen(): php_network_getaddresses: gethostbyname failed. errno=0

Filename: libraries/Email.php

Line Number: 1689 A PHP Error was encountered

Severity: Warning

Message: fsockopen(): unable to connect to ssl://smtp.googlemail.com:465 (php_network_getaddresses: gethostbyname failed. errno=0)

Filename: libraries/Email.php

Line Number: 1689 A PHP Error was encountered

Severity: Warning

Message: fwrite() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1846 A PHP Error was encountered

Severity: Warning

Message: fgets() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1869 A PHP Error was encountered

Severity: Warning

Message: fwrite() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1846 A PHP Error was encountered

Severity: Warning

Message: fgets() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1869 A PHP Error was encountered

Severity: Warning

Message: fwrite() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1846 A PHP Error was encountered

Severity: Warning

Message: fgets() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1869 A PHP Error was encountered

Severity: Warning

Message: fwrite() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1846 A PHP Error was encountered

Severity: Warning

Message: fgets() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1869 A PHP Error was encountered

Severity: Warning

Message: fwrite() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1846 A PHP Error was encountered

Severity: Warning

Message: fwrite() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1846 A PHP Error was encountered

Severity: Warning

Message: fgets() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1869 A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /base/data/home/apps/s~postleng/2.380394098175674288/ctm-hotel-system/core/Exceptions.php:185)

Filename: core/Common.php

Line Number: 442 An Error Was Encountered

The following SMTP error was encountered: 0 php_network_getaddresses: gethostbyname failed. errno=0 Unable to send data: AUTH LOGIN Failed to send AUTH LOGIN command. Error: Unable to send data: MAIL FROM:

from:

The following SMTP error was encountered: Unable to send data: RCPT TO:

to:

The following SMTP error was encountered: Unable to send data: DATA

data:

The following SMTP error was encountered: Unable to send data: User-Agent: CodeIgniter Date: Thu, 27 Nov 2014 03:57:16 -0500 From: "mydomain.com" Return-Path: To: login@gmail.com Subject: =?iso-8859-1?Q?Complete_your_registration!?= Reply-To: "myemail@gmail.com" X-Sender: myemail@gmail.com X-Mailer: CodeIgniter X-Priority: 3 (Normal) Message-ID: <5476e76cb1a8a@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="B_ALT_5476e76cb1ae4" This is a multi-part message in MIME format. Your email application may not support this format. --B_ALT_5476e76cb1ae4 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit

Please help Thank you in advance.

doucaishou0074
doucaishou0074 我检查了fsockopen()已经启用了。
接近 5 年之前 回复
dsh1956
dsh1956 您的主机是否启用了fsockopen?
接近 5 年之前 回复
douna2633
douna2633 我的猜测是url配置打开notepad++或任何编辑器让你在文件夹中查找单词并选择你的项目文件夹并查找本地主机或本地主机的名称,你可能会找到一个重要变量如常量的文件。url设置为localhost/www.yourproject.com,您需要将其更改为新域
接近 5 年之前 回复
dongyuzhu2244
dongyuzhu2244 对不起,我不明白你说的话。请告诉我你说的内容的详细信息。
接近 5 年之前 回复
donglin7979
donglin7979 是否有配置文件,您仍然需要在notepad++中为localhost重命名搜索。见htacces
接近 5 年之前 回复

1个回答

May be try using sendmail protocol?

展开翻译

译文



可以尝试使用 sendmail </ strong>协议吗?</ p>
</ div>

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!