[英]How to send email using Sendgrid with custom domain (https) with Google App Engine
我在 Google App Engine 上托管了一個用 Codeigniter (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 Compute Engine。 默認情況下,App Engine PHP 環境在您無法打開任意連接的模式下運行。
但是,請查看本指南: https : //cloud.google.com/appengine/docs/php/mail/sendgrid
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.