【问题标题】:App Engine - PHP env - 500 error while sending emailApp Engine - PHP env - 发送电子邮件时出现 500 错误
【发布时间】:2020-08-03 00:45:18
【问题描述】:

我计划将 GCP 成本发送给利益相关者。我正在使用应用引擎来托管和发送电子邮件。

https://cloud.google.com/solutions/automated-email-cloud-billing-summary

我正在使用 gcloudshell。我遇到了错误。

错误:0.0.0.1:52050 [500]:/?authuser=0&environment_name=default - 未捕获的错误:在 /home/project/billingemails/index.php 中找不到类 'google\appengine\api\mail\Message' :39 堆栈跟踪: #0 {主要} 在第 39 行的 /home/project/billingemails/index.php 中抛出'''

代码:

    <?php
    
    namespace Google\Cloud\Samples\Auth;
    
    use Google\Auth\Credentials\GCECredentials;
    use google\appengine\api\app_identity\AppIdentityService;
    use Google\Cloud\BigQuery\BigQueryClient;
    use google\appengine\api\mail\Message;
    
    
    // Variables holding your values, replace before deploying
    $datatable = "projectid.billing_data.gcp_billing_export_v1_000000_000000_000000";
    $toemail = "gcpbilling@domain.com";
    $fromemail = "your@domain.com";
    
    $message = wordwrap($message, 70, "\r\n");
    
    try {
            $mailmsg = new Message();
            $mailmsg->setSender($fromemail);
            $mailmsg->addTo($toemail);
            $mailmsg->setSubject('GCP Billing Summary');
            $mailmsg->setTextBody($message);
            $mailmsg->send();
            printf('<br>---Mail sent successfully!---<br>');
    }
    catch (InvalidArgumentException $e) {
            printf('<br>---Error occurred, could not send email---<br>');
    }
    ?>

【问题讨论】:

  • 嗨@rishi你能指出哪一行是39吗?根据堆栈跟踪,错误似乎在这一行,并且由于您的代码不像示例中那样完整,因此无法识别您的代码与本教程的代码之间的差异。除此之外,您是否确保在您的路径 `google\appengine\api\mail` 中有一个名为 Message 的类?这是您的代码中显示的另一个错误。
  • 您使用的是哪个版本的 PHP? App Engine 有可用于 5.5 的 mail API,但这些 API 在 7 中不再使用。您需要使用不同的 API 来发送邮件
  • 嗨 @gso_gabriel 第 39 行是 $mailmsg = new Message();我错过了名为 Message 的课程。所以我在 gcloudshell 上手动更新了这个类,它现在可以工作了。我使用 PHP 5.5
  • 很高兴听到它对 @rishi 有帮助 我可以发表我的评论作为答案,以便您可以接受并支持它作为正确的解决方案吗?

标签: php google-app-engine


【解决方案1】:

从堆栈跟踪(它的下面部分)看来,Message 类被遗漏了。

未捕获的错误:在 /home/project/billingemails/index.php:39 中找不到类“google\appengine\api\mail\Message”

出于这个原因,请确保这个类写得很好并且在正确的文件夹中,这样你的index.php 文件可以正确调用它并按预期发送电子邮件。等这门课来对了地方,你应该就没事了。

【讨论】:

    猜你喜欢
    • 2010-11-26
    • 1970-01-01
    • 2012-08-23
    • 2018-01-20
    • 1970-01-01
    • 2013-11-24
    • 2010-10-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多