我有一个在谷歌应用引擎上托管的web应用程序,它是用Codeigner(PHP)编写的。我使用sendgrid发送事务性电子邮件。
该应用最初托管在https://appid.appspot.com一切都很好。
我最近将应用程序URL更改为https://app.domain.com并导入了我从godaddy购买的SSL证书。就ssl证书而言,我没有任何问题。
然而,在发送事务性电子邮件时,我收到了以下错误。
Severity: Warning
Message: fsockopen(): php_network_getaddresses: gethostbyname failed. errno=0
Filename: libraries/Email.php
Line Number: 1949
Backtrace:
File: /base/data/home/apps/s~chutti-app-prod/1.388253899009796980/application/controllers/Signup.php
Line: 60
Function: send
File: /base/data/home/apps/s~chutti-app-prod/1.388253899009796980/index.php
Line: 292
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: fsockopen(): unable to connect to smtp.sendgrid.net:587 (php_network_getaddresses: gethostbyname failed. errno=0)
Filename: libraries/Email.php
Line Number: 1949
Backtrace:
File: /base/data/home/apps/s~chutti-app-prod/1.388254166863409817/application/controllers/Signup.php
Line: 60
Function: send
File: /base/data/home/apps/s~chutti-app-prod/1.388254166863409817/index.php
Line: 292
Function: require_once
sendgrid凭据与我在托管于的不同应用程序中使用的凭据相同https://app.appspot.com一切都很好。问题只出在我使用https的自定义URL上。
发送电子邮件的代码
$this->load->library('email');
$this->email->initialize(array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.sendgrid.net',
'smtp_user' => 'username',
'smtp_pass' => 'password',
'smtp_port' => 587,
'crlf' => "'r'n",
'newline' => "'r'n"
));
$body = 'some html content';
$this->email->set_mailtype("html");
$this->email->from('noreply@domain.com');
$this->email->to('to@userdomain.com');
$this->email->subject('Please confirm your email');
$this->email->message($body);
$this->email->send();
如果有人能帮我弄清楚问题到底是什么,那就太好了。
教程链接适用于Google计算引擎。默认情况下,应用程序引擎PHP环境在无法打开任意连接的模式下运行。
但是,请查看本指南:https://cloud.google.com/appengine/docs/php/mail/sendgrid