【问题标题】:Use PHP Variable as Email Destination in SES在 SES 中使用 PHP 变量作为电子邮件目的地
【发布时间】:2025-11-25 01:25:01
【问题描述】:

我想使用 aws php sdk 将 php 变量用作 Amazon SES 的目标电子邮件...以下是相关的代码行

$email = new AmazonSES();

$recip = array("ToAddresses"=>"$email");
$message = array("Subject.Data"=>"Welcome to Weather Warnings","Body.Text.Data"=>"tester");
$email->send_email("me@mydomain.com",$recip, $message);

我的错误是.... 设置 recip 变量的行是第 31 行

可捕获的致命错误:无法将 AmazonSES 类的对象转换为第 31 行 /home/websites/wxwarn/customer/register.php 中的字符串

【问题讨论】:

    标签: php sdk amazon-web-services


    【解决方案1】:

    $email 是 AmazonSES 的类型,所以它不能是电子邮件地址 您必须使用另一个变量作为地址

    您好,我不在家,无法查看我的代码,但我认为您必须输入:

    $email_array = array("test@test.com","test@test.net");
    $recip = array("ToAddresses"=>"$email_array");
    

    看这里:

    http://www.alexkorn.com/blog/2011/04/sending-email-aws-php-with-amazonses/

    【讨论】:

      【解决方案2】:

      我不熟悉 AmazonSES,但它是一个对象而不是字符串,因此您必须执行类似 $recip = array("ToAddresses"=>$email->getEmail()); 的操作

      如果您要在 AmazonSES 对象中创建 __toString() 魔术方法,并让它返回电子邮件地址(假设它是该对象的属性),我认为您所拥有的会起作用。

      【讨论】:

        【解决方案3】:

        这对我有用:

        require_once('ses.php');
        $ses = new SimpleEmailService('accessKey', 'secretKey');
        $m = new SimpleEmailServiceMessage();
        $m->addTo('addressee@example.com');
        $m->setFrom('Name <yourmail@example.com>');
        $m->setSubject('You have got Email!');
        $m->setMessageFromString('Your message');
        $ses->sendEmail($m);
        

        你可以从http://www.orderingdisorder.com/aws/ses/获取ses.php

        【讨论】: