I'm trying to send my first email with Sendgrid:
$sendgrid = new SendGrid('username', 'xx.xxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxx_xxxxxxxxxxxxxxxxxx');
$email = new SendGrid\Email();
$email->addTo("[email protected]")
->setFrom("[email protected]")
->setSubject("Sending with SendGrid is Fun")
->setHtml("and easy to do anywhere, even with PHP");
Here's the error I run into:
PHP Fatal error: Uncaught exception 'SendGrid\Exception' with message '{"errors":["Bad username / password"],"message":"error"}'
Instead of 'username' and 'xx.xxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxx_xxxxxxxxxxxxxxxxxx' I of course use real API key info from Sendgrid settings:
I used the long string key provided after creating the API key. But there still seems to be something wrong with this line: $sendgrid = new SendGrid('username', 'xx.xxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxx_xxxxxxxxxxxxxxxxxx');
Where should I get the info for authorization so that I don't get the Bad username / password error?
SendGrid supports Basic Authentication using an API key as your password value for some services. When using Basic Authentication, your username will always be "apikey," and your password will be your API key.
Your application, mail client, or website can all use API (Application Programming Interface) keys to authenticate access to SendGrid services. They are the preferred alternative to using a username and password because you can revoke an API key at any time without having to change your username and password.
Another possible answer is to pass just the api key to the SendGrid() constructor;
$sendgrid = new SendGrid('xx.xxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxx_xxxxxxxxxxxxxxxxxx');
$email = new SendGrid\Email();
$email->addTo("[email protected]")
->setFrom("[email protected]")
->setSubject("Sending with SendGrid is Fun")
->setHtml("and easy to do anywhere, even with PHP");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With