为了账号安全,请及时绑定邮箱和手机立即绑定

在 null 上调用成员函数 sendEmail()

在 null 上调用成员函数 sendEmail()

PHP
波斯汪 2022-01-14 17:10:41
我正在使用 AWS 示例来调用适用于 PHP 的 AWS 开发工具包。将代码转换为函数时,出现以下错误:未捕获错误:调用成员函数 sendEmail()第 41 行似乎是问题所在: $result = $SesClient->sendEmail([我尝试删除结果变量并注释掉它的用法当我运行代码并且它不是一个正常工作的函数时,我不确定我在这里做错了什么,我确信这可能是一个简单的错误。我在这里先向您的帮助表示感谢<?php// If necessary, modify the path in the require statement below to refer to the // location of your Composer autoload.php file.require '/vendor/autoload.php';use Aws\Ses\SesClient;use Aws\Exception\AwsException;// Create an SesClient. Change the value of the region parameter if you're // using an AWS Region other than US West (Oregon). Change the value of the// profile parameter if you want to use a profile in your credentials file// other than the default.$SesClient = new SesClient([    'profile' => 'default',    'version' => '2010-12-01',    'region'  => 'us-east-1']);function send_email($recipient, $message, $subject){    // Replace sender@example.com with your "From" address.    // This address must be verified with Amazon SES.    $sender_email = 'sender@gmail.com';    // Replace these sample addresses with the addresses of your recipients. If    // your account is still in the sandbox, these addresses must be verified.    // $recipient_emails = ['recipient1@example.com','recipient2@example.com'];    $recipient_emails = [$recipient];    // Specify a configuration set. If you do not want to use a configuration    // set, comment the following variable, and the    // 'ConfigurationSetName' => $configuration_set argument below.    // $configuration_set = 'ConfigSet';    $subject = $subject;    $plaintext_body = $message.PHP_EOL.'This email was sent with Amazon SES using the AWS SDK for PHP.' ;    $html_body =  '<h1>'.$message.'</h1>';    $char_set = 'UTF-8';
查看完整描述

2 回答

?
翻阅古今

TA贡献1780条经验 获得超5个赞

尝试在 send_email 函数中声明 $SesClient


查看完整回答
反对 回复 2022-01-14
?
一只名叫tom的猫

TA贡献1906条经验 获得超3个赞

它在没有函数的情况下工作,因为您在函数之外声明了 $SesClient 。在函数之后声明它 - 或通过它传递给函数


function function send_email($recipient, $message, $subject, $SesClient) {

/* snip */

}


echo send_email('test@gmail.com', 'test', 'test subject', $SesClient);


查看完整回答
反对 回复 2022-01-14
  • 2 回答
  • 0 关注
  • 123 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信