Php Mail无法在Google App Engine Flex上运行(不显示错误)

Php Mail无法在Google App Engine Flex上运行(不显示错误)

问题描述:

我有一个在Google App Engine flex上运行的wordpress网站.我正在尝试将php mail()函数用于简单的联系表单.

I have a wordpress site running on Google App Engine flex. I'm trying to use the php mail() function for a simple contact form.

我有一个像这样的方块:

I have a block like so:

   if ( mail( $to, $subject, $message, $headers ) ) {
      //stuff
   } else {
      error_reporting(-1);
      ini_set('display_errors', 'On');
      set_error_handler("var_dump");
      var_dump(error_get_last());
      echo '<pre>';
      print_r (error_get_last());
      echo '</pre>';
   }

我尝试使用不同的$ from电子邮件没有运气.我得到显示为响应的NULL错误消息.这些是我正在使用的设置.我尝试使用我的admin @gmail帐户,现在切换到appsot @ gservice.我没有在仪表板上记录任何与邮件相关的项目

I've tried using different $from emails with no luck. I get a NULL error message displayed in response. These are settings i'm using. I've tried using my admin @gmail account and now switched to the appsot@gservice. I don't see any mail related items logged in dashboard

$to = 'myemail@gmail.com';
$from = "my-project@appspot.gserviceaccount.com";
$subject = "New Application";
$message = 'test';
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: ".$from."\r\n"."X-Mailer: php";

请记住,这是flex环境. Google似乎只有使用第三方服务发送批量电子邮件的指南.

Keep in mind this is the flex environment. Google only seems to have guides on using third party services for sending bulk email.

此邮件功能应该正常工作吗?我必须编辑我的app.yaml或php.ini吗?

this mail function should work right? Do I have to edit my app.yaml or php.ini?

App.yaml

runtime: php
env: flex

manual_scaling:
  instances: 1

handlers:
- url: /(.*\.(htm|html|css|js))$
  static_files: wordpress/\1
  upload: wordpress/.*\.(htm|html|css|js)$
  application_readable: true

- url: /wp-content/(.*\.(ico|jpg|jpeg|png|gif|woff|ttf|otf|eot|svg))$
  static_files: wordpress/wp-content/\1
  upload: wordpress/wp-content/.*\.(ico|jpg|jpeg|png|gif|woff|ttf|otf|eot|svg)$
  application_readable: true

- url: /(.*\.(ico|jpg|jpeg|png|gif|woff|ttf|otf|eot|svg))$
  static_files: wordpress/\1
  upload: wordpress/.*\.(ico|jpg|jpeg|png|gif|woff|ttf|otf|eot|svg)$
  application_readable: true

- url: /wp-includes/images/media/(.*\.(ico|jpg|jpeg|png|gif|woff|ttf|otf|eot|svg))$
  static_files: wordpress/wp-includes/images/media/\1
  upload: wordpress/wp-includes/images/media/.*\.(ico|jpg|jpeg|png|gif|woff|ttf|otf|eot|svg)$
  application_readable: true

- url: /wp-admin/(.+)
  script: wordpress/wp-admin/\1
  secure: always

- url: /wp-admin/
  script: wordpress/wp-admin/index.php
  secure: always

- url: /wp-login.php
  script: wordpress/wp-login.php
  secure: always

- url: /wp-cron.php
  script: wordpress/wp-cron.php
  login: admin

- url: /xmlrpc.php
  script: wordpress/xmlrpc.php

- url: /wp-(.+).php
  script: wordpress/wp-\1.php

- url: /(.+)?/?
  script: wordpress/index.php

beta_settings:
  cloud_sql_instances: myproject-:us-east4:my-instance

runtime_config:
  document_root: wordpress
  skip_lockdown_document_root: true

env_variables:
  WHITELIST_FUNCTIONS: escapeshellarg,escapeshellcmd,exec,pclose,popen,shell_exec,phpversion,php_uname

php.ini

extension=bcmath.so
extension=gd.so
zend_extension=opcache.so
short_open_tag=On
upload_max_filesize = 200M
google_app_engine.disable_readonly_filesystem = 1

无法在标准环境之外使用App Engine Mail服务.我确实引用了官方文档:

It is not possible to use App Engine Mail service outside standard environment. I literally cite the official documentation:

App Engine Mail服务在标准之外不可用 环境.您将需要使用第三方邮件提供商,例如 SendGrid Mailgun Mailjet 发送电子邮件.所有的 这些服务提供API来从正在运行的应用程序发送电子邮件 任何地方.

The App Engine Mail service is not available outside the standard environment. You will need to use a third-party mail provider such as SendGrid, Mailgun, or Mailjet to send email. All of these services offer APIs to send email from applications running anywhere.

以下指南显示了如何通过灵活的方式使用这些服务 环境:

The following guides show how to use these services with the flexible environment:

使用SendGrid发送电子邮件

使用Mailgun发送电子邮件

使用Mailjet发送电子邮件