Recoverable fatal error: Object of class SendGrid\Mail\Mail could not be converted to string
Recoverable fatal error: Object of class SendGrid\Mail\Mail could not be converted to string
我正在尝试使用 SendGrid 的 PHP 库传递动态值。当我传入一个字符串但我添加一个动态值时它起作用,我得到这个错误
可恢复的致命错误:class SendGrid\Mail\Mail 的对象无法在第 30 行的 C:\xampp\htdocs\new\vendor\sendgrid\sendgrid\lib\helper\Assert.php 中转换为字符串
这个有效
$email = new \SendGrid\Mail\Mail();
$email->setFrom("support@example.com", "example");
$email->setSubject("IMPORTANT: Signal failure");
$email->addTo("user@exampl.com", "{$fname}");
$email->addContent("text/plain", "{$message}");
$email->addContent(
"text/html", "{$message}"
);
$sendgrid = new \SendGrid('APIKEY');
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 = new \SendGrid\Mail\Mail();
$email->setFrom("support@example.com", "example");
$email->setSubject("IMPORTANT: Signal failure");
$email->addTo("{$email}", "{$fname}"); //this line causes the error
$email->addContent("text/plain", "{$message}");
$email->addContent(
"text/html", "{$message}"
);
$sendgrid = new \SendGrid('APIKEY');
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
不是包含电子邮件地址的字符串。它是 \SendGrid\Mail\Mail()
.
的实例
Calling it as a string won't work, because it looks like \SendGrid\Mail\Mail()
does not implement the Stringable interface.
您可以通过使用更好的变量名来防止此类事故发生,例如
$mailer = new \SendGrid\Mail\Mail();
或
$sendGridMail = new \SendGrid\Mail\Mail();
我正在尝试使用 SendGrid 的 PHP 库传递动态值。当我传入一个字符串但我添加一个动态值时它起作用,我得到这个错误 可恢复的致命错误:class SendGrid\Mail\Mail 的对象无法在第 30 行的 C:\xampp\htdocs\new\vendor\sendgrid\sendgrid\lib\helper\Assert.php 中转换为字符串
这个有效
$email = new \SendGrid\Mail\Mail();
$email->setFrom("support@example.com", "example");
$email->setSubject("IMPORTANT: Signal failure");
$email->addTo("user@exampl.com", "{$fname}");
$email->addContent("text/plain", "{$message}");
$email->addContent(
"text/html", "{$message}"
);
$sendgrid = new \SendGrid('APIKEY');
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 = new \SendGrid\Mail\Mail();
$email->setFrom("support@example.com", "example");
$email->setSubject("IMPORTANT: Signal failure");
$email->addTo("{$email}", "{$fname}"); //this line causes the error
$email->addContent("text/plain", "{$message}");
$email->addContent(
"text/html", "{$message}"
);
$sendgrid = new \SendGrid('APIKEY');
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
不是包含电子邮件地址的字符串。它是 \SendGrid\Mail\Mail()
.
Calling it as a string won't work, because it looks like
\SendGrid\Mail\Mail()
does not implement the Stringable interface.
您可以通过使用更好的变量名来防止此类事故发生,例如
$mailer = new \SendGrid\Mail\Mail();
或
$sendGridMail = new \SendGrid\Mail\Mail();