Reputation: 65
Trying to use Sendgrid's API (running on bluemix) to send automated emails.
$sendgrid_username = 'XXXXXXXXX';
$sendgrid_password = 'XXXXXXXXXXXXXXX';
$to = $_SESSION['emailto'];
$from = "[email protected]";
$sendgrid = new SendGrid($sendgrid_username, $sendgrid_password, array("turn_off_ssl_verification" => true));
$email = new SendGrid\Email();
$email->addTo($to)->
setFrom($from)->
setSubject('Password Reset')->
setHtml("<b>A new password has been set for the user: %mailto%.<br> The new password is: %pass%<br><br></b>")->
addSubstitution("%mailto%", array($_SESSION['emailto']))->
addSubstitution("%pass%", array($random_pass_clear))->
addHeader('X-Sent-Using', 'SendGrid-API')->
addHeader('X-Transport', 'web')->
$response = $sendgrid->send($email); //this is line 21
I've used the example code from Sendgrid and everything is working (email i being sent). I do however get 2 errors:
PHP NOTICE: Undefined Variable response on line 21
PHP FATAL ERROR: Cannot access empty property on line 21
I've never encountered the second error before and I'm kind of confused as to what is going on... any idea's where I went wrong?
Upvotes: 2
Views: 131
Reputation: 7694
addHeader('X-Transport', 'web')->
this excess T_OBJECT_OPERATOR
(->
) on line 20 is your bad guy.
It tries to use a $response
variable in $email
object on line 21.
Ignoring previous chaining, it essentially is trying to do this:
$email->$response = $sendgrid->send($email);
The sending is done, but it fails to put the method-result in the $email->$response
variable (Cannot access empty property) because $email->$response
is never defined (Undefined Variable)
Upvotes: 5