0
我正在使用發送網格向服務器webmail發送電子郵件。以下是我的代碼。我按照教程編寫了這段代碼。但我得到的錯誤:使用Sendgrid api發送電子郵件
Warning: rawurlencode() expects parameter 1 to be string, object given in /home/cwtestco/public_html/demo/active-fit-club/sendgrid-php/vendor/guzzle/guzzle/src/Guzzle/Http/QueryString.php on line 237
Warning: Cannot modify header information - headers already sent by (output started at /home/cwtestco/public_html/demo/active-fit-club/sendgrid-php/vendor/guzzle/guzzle/src/Guzzle/Http/QueryString.php:237) in /home/cwtestco/public_html/demo/active-fit-club/index.php on line 53
代碼:使用下面的代碼和它的工作
if($res != false){
require_once ($_SERVER['DOCUMENT_ROOT'].'/demo/active-fit-club/sendgrid-php/vendor/autoload.php');
require_once ($_SERVER['DOCUMENT_ROOT'].'/demo/active-fit-club/sendgrid-php/lib/SendGrid.php');
require_once ($_SERVER['DOCUMENT_ROOT'].'/demo/active-fit-club/sendgrid-php/lib/SendGrid/Exception.php');
$message = "Name : $name <br> Email : $email <br> Mobile : $mobile";
$sendgrid = new SendGrid('myapikey');
$email = new SendGrid\Email();
$email
->addTo("[email protected]")
->setFrom($email)
->setSubject("Contact mail")
->setHtml($message);
try {
$sendgrid->send($email);
$_SESSION['success'] = true;
header("location:url");
exit;
} catch(\SendGrid\Exception $e) {
// echo $e->getCode();
// foreach($e->getErrors() as $er) {
// echo $er;
// }
header("location:url");
exit;
}
}
其中api如果不是API。應該有用戶和密碼,但您只使用密碼。 – user254153
我做了修改。不需要用戶名和密碼。你可以使用apiKey – Tamil