This documentation provides examples for specific use cases. Please [open an issue](https://github.com/sendgrid/sendgrid-php/issues) or make a pull request for any use cases you would like us to document here. Thank you! # Table of Contents * [Attachments](#attachments) * [Transactional Templates](#transactional_templates) # Attachments Here is an example of attaching a text file to your email, assuming that text file `my_file.txt` is located in the same directory. ```php setContent($file_encoded); $attachment->setType("application/text"); $attachment->setDisposition("attachment"); $attachment->setFilename("my_file.txt"); $mail = new SendGrid\Mail($from, $subject, $to, $content); $mail->addAttachment($attachment); $apiKey = getenv('SENDGRID_API_KEY'); $sg = new \SendGrid($apiKey); $response = $sg->client->mail()->send()->post($mail); echo $response->statusCode(); echo $response->headers(); echo $response->body(); ?> ``` # Transactional Templates For this example, we assume you have created a [transactional template](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). Following is the template content we used for testing. Template ID (replace with your own): ```text 13b8f94f-bcae-4ec6-b752-70d6cb59f932 ``` Email Subject: ```text <%subject%> ``` Template Body: ```html Hello -name-,

I'm glad you are trying out the template feature!

<%body%>

I hope you are having a great day in -city- :)

``` ## With Mail Helper Class ```php body tag"); $mail = new SendGrid\Mail($from, $subject, $to, $content); $mail->personalization[0]->addSubstitution("-name-", "Example User"); $mail->personalization[0]->addSubstitution("-city-", "Denver"); $mail->setTemplateId("13b8f94f-bcae-4ec6-b752-70d6cb59f932"); $apiKey = getenv('SENDGRID_API_KEY'); $sg = new \SendGrid($apiKey); try { $response = $sg->client->mail()->send()->post($mail); } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } echo $response->statusCode(); echo $response->headers(); echo $response->body(); ``` ## Without Mail Helper Class ```php body tag" } ], "template_id": "13b8f94f-bcae-4ec6-b752-70d6cb59f932" }'); $apiKey = getenv('SENDGRID_API_KEY'); $sg = new \SendGrid($apiKey); try { $response = $sg->client->mail()->send()->post($request_body); } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } echo $response->statusCode(); echo $response->body(); echo $response->headers(); ```