我确信这是一个简单的解决方案,我正在尝试设置sendgrid以发送确认电子邮件。
require 'sendgrid-php/vendor/autoload.php';
$sendgrid = new SendGrid($user,$pass);
$email = new SendGrid\Email();
$email->addTo($sEmail)
->setFrom($email)
->setSubject("Sending with SendGrid is Fun")
->setHtml("and easy to do anywhere, even with PHP");
$sendgrid->send($email);
执行代码后,我收到以下错误消息:
Warning: Missing argument 1 for SendGrid\Email::__construct()
我正在运行PHP 5.6.16版
我确信我错过了一些愚蠢的事情
答案 0 :(得分:2)
SendGrid-PHP库已有一些更新。请参阅自述文件中的示例:https://github.com/sendgrid/sendgrid-php
<?php
// If you are using Composer
require 'vendor/autoload.php';
// If you are not using Composer (recommended)
// require("path/to/sendgrid-php/sendgrid-php.php");
$from = new SendGrid\Email(null, "test@example.com");
$subject = "Hello World from the SendGrid PHP Library!";
$to = new SendGrid\Email(null, "test@example.com");
$content = new SendGrid\Content("text/plain", "Hello, Email!");
$mail = new SendGrid\Mail($from, $subject, $to, $content);
$apiKey = getenv('SENDGRID_API_KEY');
$sg = new \SendGrid($apiKey);
$response = $sg->client->mail()->send()->post($mail);
echo $response->statusCode();
echo $response->headers();
echo $response->body();
由于$email = new SendGrid\Email();
需要两个https://github.com/sendgrid/sendgrid-php/blob/master/lib/helpers/mail/Mail.php#L845 $name
$email
和$name
参数,因此您收到该错误。
null
如果您不想要姓名,可以离开$sendgrid = new SendGrid($user,$pass);
。
此外,不推荐使用class Triangle : public Polygon
{
public:
Triangle(Point, Point, Point);
~Triangle();
private:
};
等用户名和密码,请参阅此处:https://github.com/sendgrid/sendgrid-php/blob/master/lib/SendGrid.php#L34
您需要创建一个API密钥并使用它。见这里:https://app.sendgrid.com/settings/api_keys
答案 1 :(得分:0)
我也在处理类似的发送网格问题。
我通过添加以下标题来实现它。
&#34; Content-Type&#34;:&#34; application / json;字符集= UTF8&#34;