在 SES 中使用 PHP 变量作为电子邮件目标


Use PHP Variable as Email Destination in SES

我想使用 php 变量作为使用 aws php sdk 的 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);

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

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

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

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

$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/

我不熟悉 AmazonSES,但它是一个对象而不是一个字符串,所以你必须做类似 $recip = array("ToAddresses"=>$email->getEmail());

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

这对

我有用:

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