首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >sendgrid Sendat立即发送

sendgrid Sendat立即发送
EN

Stack Overflow用户
提问于 2022-10-24 19:27:41
回答 1查看 38关注 0票数 0

我正在努力将Sendgrid集成到我的php应用程序中。我的发送脚本正在工作,除了它的调度部分。我刚开始使用sendgrid并整合它们的脚本。

代码语言:javascript
复制
    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 )

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-10-24 20:09:45

如我所见:https://github.com/sendgrid/sendgrid-php/blob/main/lib/mail/Mail.php

Mail()构造函数定义没有$sendat参数。

您需要使用setSendAt()方法。

所以,试试这个:

代码语言:javascript
复制
$email = new Mail(
    $from,
    $tos,
    $subject, // or array of subjects, these take precedence
    $plainTextContent,
    $htmlContent,
    $globalSubstitutions
);
$email->setSendAt($sendat);

另外,您不需要实例化SendAt对象,因为这是在setSendAt()方法中自动完成的。所以,你可以:

代码语言:javascript
复制
$sendat = 1666639700; //Instead of new SendAt(1666639700);

或者直接删除$sendat变量并执行以下操作:

代码语言:javascript
复制
$email->setSendAt(1666639700);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74185894

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档