【问题标题】:Php Mail wont work on Google App Engine Flex (no errors displayed)Php Mail 无法在 Google App Engine Flex 上运行(不显示错误)
【发布时间】:2018-05-31 15:02:59
【问题描述】:

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

我有一个这样的块:

   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 错误消息作为响应显示。这些是我正在使用的设置。我尝试使用我的管理员@gmail 帐户,现在切换到appsot@gservice。我没有在仪表板中看到任何与邮件相关的项目

$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 似乎只有使用第三方服务发送批量电子邮件的指南。

这个邮件功能应该可以正常工作吧?我是否必须编辑我的 app.yaml 或 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

【问题讨论】:

    标签: php google-app-engine


    【解决方案1】:

    不能在标准环境之外使用 App Engine 邮件服务。我从字面上引用official documentation

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

    以下指南展示了如何灵活地使用这些服务 环境:

    Sending emails with SendGrid

    Sending emails with Mailgun

    Sending emails with Mailjet

    【讨论】:

    • 感谢您的回复。我以为那是指他们的邮件 api 服务。这很令人困惑,因为他们建议使用那些主要用于发送批量电子邮件的第三方服务,而我所需要的只是一个简单的 mail() 到指定的电子邮件。再次感谢
    猜你喜欢
    • 1970-01-01
    • 2014-10-16
    • 2020-01-07
    • 1970-01-01
    • 2017-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-20
    相关资源
    最近更新 更多