Q:

SendGrid - Efficient Real Estate Email Composition

I'm trying to do the following using the latest SendGrid php information found here.
For a real estate portal, let's say a few people (5) are interested in an open house in Florida, represented by a real estate agent. An array includes their emails like this $prospect_email_array[], names like this $prospect_name[], realtor like this $realtor, and location like this $location. What would be the appropriate way to send an email out to them, in one go, as blind copies (so no prospect sees other prospects email addresses), efficiently. I am looking for comprehensive code to accomplish this. So far, on the php side, I have this pseudo code:
   To: $prospect_email_array[]
 From: mail@realestatesite.com
Title: $realtor's Open House in $location Welcome
 Body: 
       Dear $prospect_name[],

       I hope to see you in our upcoming open house in $location.

       Looking forward to seeing you there!

       Best Wishes,
       $realtor

In addition, having a plain text version and html version is what I'm after. Will the equivilant of 2 'br' tags be preserved in plain text? Are 2 'br' tags needed in the html version for spacing as above? There may be emails for open houses, house interest, and potential buyers. Would these be the categories to use in SendGrid? Also, is utf-8 supprorted by default, or do we need to pass something to SendGrid?

A:

Here's some "pseudo code" that should accomplish most of what you're trying to do.  I haven't tested this at all and it's quite possible that there are typos and irregularities in it.  It should get you moving in the right direction though.
<?php

include 'path/to/sendgrid-php/SendGrid_loader.php';

$sendgrid = new SendGrid('username', 'password');

$mail = new SendGrid\Mail();
$mail->setFrom('mail@realestatesite.com')->
       setSubject($realtor . "'s Open House in " . $location)->
       setText('[Fill this in yourself as an exercise]')->
       setHtml('Dear %name%,<br />I hope to see you in our upcoming open house in ' . $location . '. <br /> Looking forward to seeing you there! <br /> Best Wishes, <br />' . $realtor);  

$mail->setRecipientsInHeader(true);

foreach ($prospect_email_array as $prospect) {
  $mail->addTo($prospect);
}

$mail->addSubstitution("%name%", $prospect_name);
$sendgrid->smtp->send($mail);

