sendgrid-php: Does not contain a valid address
I am trying to call the php script to send email using sendgrid by passing to/from email address and API key as a parameter.
It throws an error saying {"errors":[{"message":"Does not contain a valid address.","field":"personalizations.0.to.0.email","help":"http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#message.personalizations.to"}]}
And on hard-coding the to address, it works flawlessly.
I have also used the same technique in setting the from address and API key which works without any problem, the only error seems to be in the from address.
Code :
require 'vendor/autoload.php';
$from = new SendGrid\Email(null,$argv[2]); //No issues here
$subject = "Hello World from the SendGrid PHP Library!";
$to = new SendGrid\Email(null, $argv[5]); //Throws the above mentioned error
$content = new SendGrid\Content("text/plain","Hello"); //I get the same error on replacing the content too with a variable passed to the script
$mail = new SendGrid\Mail($from, $subject, $to, $content);
$apiKey = $argv[1];
$sg = new \SendGrid($apiKey);
$response = $sg->client->mail()->send()->post($mail);
echo $response->statusCode();
echo $response->headers();
echo $response->body();``
My PHP version is `PHP 5.6.23-1`
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 22 (11 by maintainers)
No issues, Thank you for being so patient and helping me out 😃 Cheers.