我确信这是一个简单的解决方案,我正在尝试设置一个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
我确信我错过了一些愚蠢的事情。
发布于 2016-08-04 20:14:42
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);这样的用户名和密码的使用也被弃用,请参阅此处:https://github.com/sendgrid/sendgrid-php/blob/master/lib/SendGrid.php#L34
您需要创建一个API密钥并使用它。查看此处:https://app.sendgrid.com/settings/api_keys
发布于 2017-02-10 15:30:45
我也在为send grid处理类似的问题。
我通过添加下面的头来让它工作。
"Content-Type":“应用程序/json;charset=utf8”
https://stackoverflow.com/questions/38751471
复制相似问题