我正在努力将Sendgrid集成到我的php应用程序中。我的发送脚本正在工作,除了它的调度部分。我刚开始使用sendgrid并整合它们的脚本。
require '../sendgrid/vendor/autoload.php'; // If you're using Composer (recommended)
use SendGrid\Mail\From;
use SendGrid\Mail\HtmlContent;
use SendGrid\Mail\Mail;
use SendGrid\Mail\PlainTextContent;
use SendGrid\Mail\To;
use SendGrid\Mail\SendAt;
$from = new From("hello@tigerrocklincoln.com", "Tiger-Rock");
$tos= [new To(
"$email",
"$first $last",
[
'{{First_Name}}' => $first,
'{{Last_Name}}' => $last,
'{{X_Days}}' => $days,
],
"We Miss You"
),
]
$globalSubstitutions = [
'-time-' => "2018-05-03 23:10:29"
];
$plainTextContent = new PlainTextContent(
"$phrase"
);
$htmlContent = new HtmlContent(
"$phrase"
);
$sendat=new SendAt(1666639700);
print_r($sendat);
$email = new Mail(
$from,
$tos,
$subject, // or array of subjects, these take precedence
$plainTextContent,
$htmlContent,
$globalSubstitutions,
$sendat
);
$sendgrid = new \SendGrid('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');
try {
$response = $sendgrid->send($email);
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: '. $e->getMessage(). "\n";
}$email、$first等在$tos区域将被实际信息所取代。
我是否试图适当地整合sendat功能?或者有人能就如何让它发挥作用提供任何建议呢?sendat的打印结果如下:
SendGrid\Mail\SendAt对象( send_at:SendGrid\Mail\SendAt:private => 1666639700 )
发布于 2022-10-24 20:09:45
如我所见:https://github.com/sendgrid/sendgrid-php/blob/main/lib/mail/Mail.php
Mail()构造函数定义没有$sendat参数。
您需要使用setSendAt()方法。
所以,试试这个:
$email = new Mail(
$from,
$tos,
$subject, // or array of subjects, these take precedence
$plainTextContent,
$htmlContent,
$globalSubstitutions
);
$email->setSendAt($sendat);另外,您不需要实例化SendAt对象,因为这是在setSendAt()方法中自动完成的。所以,你可以:
$sendat = 1666639700; //Instead of new SendAt(1666639700);或者直接删除$sendat变量并执行以下操作:
$email->setSendAt(1666639700);https://stackoverflow.com/questions/74185894
复制相似问题