我正在尝试从我的Codeigniter项目发送电子邮件。它在我的localserver XAMP上运行。但不是在线服务器上工作

时间:2015-08-11 17:59:12

标签: php codeigniter email smtp phpmailer

我正在尝试从我的Codeigniter项目发送电子邮件。它在我的localserver XAMP上运行。但是没有在在线服务器上工作。

显示此错误...

  

遇到PHP错误严重性:警告消息:fsockopen():无法连接到ssl://smtp.googlemail.com:465(尝试对无法访问的网络执行套接字操作。)文件名:libraries / Email。 php行号:1690

我的电子邮件配置文件application / config / email.php是......

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 $config['protocol']='smtp';
 $config['smtp_host']='ssl://smtp.googlemail.com';
 $config['smtp_port']='465';
 $config['smtp_timeout']='30';
 $config['smtp_user']='********@gmail.com';
 $config['smtp_pass']='*******';
 $config['charset']='utf-8';
 $config['newline']="\r\n";
 ?>

拜托,帮助我。高级谢谢。

2 个答案:

答案 0 :(得分:1)

如果您使用自己的域名在网络上传代码,那么为什么您使用Google的邮件ID发送邮件。为什么不用自己的网络邮件?

以下代码可供我从我自己的域发送邮件。在控制器中编写此代码,或在配置中仅使用$ config,在控制器中编写剩余代码。

$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'UTF-8';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';

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

$this->email->from(ADMIN_EMAIL_ID, MY_DOMAIN);
$this->email->bcc(BCC_EMAIL_ID, MY_DOMAIN);
$this->email->to($targeEmail);
$this->email->subject(EMAIL_SUBJECT);
$this->email->message(EMAIL_MESSAGE);

if ($this->email->send())
{
   $status = 'send';
}
else
{
   $status = 'notsend';
}                

答案 1 :(得分:1)

这意味着您的DNS无法运行(它不知道smtp.googlemail.com在哪里),或者它确实知道它在哪里但它没有响应(不太可能),或者它正在响应,但是您的服务器被阻止访问它。 ISP(例如GoDaddy)通常会阻止出站电子邮件,连接到SMTP目标端口(如25,465和587)的任何内容。有时此限制仅适用于PHP二进制文件,其他程序(如telnet)可以正常工作。 / p>

虽然它不是一回事,但您可能会发现the PHPMailer troubleshooting docs对于诊断您的问题非常有用。