简体   繁体   English

如何使用带有自定义域 (https) 的 Sendgrid 和 Google App Engine 发送电子邮件

[英]How to send email using Sendgrid with custom domain (https) with Google App Engine

I'm have a web app hosted on Google App Engine written in Codeigniter (PHP).我在 Google App Engine 上托管了一个用 Codeigniter (PHP) 编写的网络应用程序。 I use sendgrid to send transactional emails.我使用 sendgrid 发送交易电子邮件。

The app was initially hosted on https://appid.appspot.com and the everything was fine.该应用程序最初托管在https://appid.appspot.com 上,一切都很好。

I recently changed the app URL to https://app.domain.com and imported a SSL certificate that I purchased from godaddy.我最近将应用程序 URL 更改为https://app.domain.com并导入了我从 Godaddy 购买的 SSL 证书。 As far as the ssl certificate is concerned I do not have any issue.就 ssl 证书而言,我没有任何问题。

However while sending transactional email I get the following error.但是,在发送交易电子邮件时,我收到以下错误。

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

The sendgrid credentials are same as I used the same credentials in a different application hosted at https://app.appspot.com and everything is fine. sendgrid 凭据与我在托管在https://app.appspot.com的不同应用程序中使用的相同凭据相同,一切都很好。 The problem is only with my custom URL with https.问题仅在于我带有 https 的自定义 URL。

Code that sends email发送电子邮件的代码

$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();

It would be great if someone can help me understand what exactly is the issue.如果有人能帮助我了解问题究竟是什么,那就太好了。

The tutorial link is for Google Compute Engine.教程链接适用于 Google Compute Engine。 By default, the App Engine PHP environment runs in a mode where you won't be able to open arbitrary connections.默认情况下,App Engine PHP 环境在您无法打开任意连接的模式下运行。

But, check out this guide instead: https://cloud.google.com/appengine/docs/php/mail/sendgrid但是,请查看本指南: https : //cloud.google.com/appengine/docs/php/mail/sendgrid

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM