sendgrid / sendgrid-php

The Official Twilio SendGrid PHP API Library
https://sendgrid.com
MIT License
1.49k stars 623 forks source link

I don't receive my email subject when sending email using dynamic template data #1039

Closed cindyadonia closed 3 years ago

cindyadonia commented 3 years ago

Issue Summary

I'm trying to send email with dynamic template data, and It works fine, I can receive my email. But, I don't see the email subject that I have set.

I'm developing this with Laravel 7

Here is how I send the email

$email = new \SendGrid\Mail\Mail(); 
$email->setFrom(env('MAIL_FROM_ADDRESS'), env('MAIL_FROM_NAME'));
$email->setSubject($subject);
$email->setTemplateId($templateId);
$email->addDynamicTemplateDatas($data);
$email->addTo("someone_email@email.com");

$sendgrid = new \SendGrid(env('MAIL_PASSWORD'));
$response = $sendgrid->send($email);

I tried to dump the data : dd($email); And this is what I got image

Can someone tell me, what went wrong? Because this is only happened when I try to send the mail using the dynamic template

Technical details:

shwetha-manvinkurke commented 3 years ago

@cindyadonia Have you actually set the subject in your template?

image

cindyadonia commented 3 years ago

@cindyadonia Have you actually set the subject in your template?

image

Hello, No I didn't, because I want to set my subject dynamically from the server.

I managed to solve my problem by sending the subject into the dynamicTemplateData array as suggested on this disccussion

Looks like SendGrid it self hasn't mention anything about this problem until today, because I cannot find any documentation saying that we have to send the subject into the dynamicTemplateData (if you are using dynamic template to send the mail)