Jump to content

searls03

Members
  • Posts

    907
  • Joined

  • Last visited

Everything posted by searls03

  1. I am working on trying to integrate send grid into my website. I am a bit newer at this. I am working on trying to set up batchids and scheduled sending (sendAt). Scheduling works when there is only one email that it is going to, however It will send right away when there is more than one email. Can anyone offer any assistance on how to get this properly set up? require '../sendgrid/vendor/autoload.php'; // If you're using Composer (recommended) use SendGrid\Mail\From; use SendGrid\Mail\HtmlContent; use SendGrid\Mail\Mail; use SendGrid\Mail\PlainTextContent; use SendGrid\Mail\To; use SendGrid\Mail\SendAt; use SendGrid\Mail\BatchId; $from = new From("email", "name"); $sql1 = "SELECT * from database where sent='no'"; $tos=array(); $result1 = $conn->query($sql1); if ($result1->num_rows > 0) { // output data of each row while($row1 = $result1->fetch_assoc()) { $first= $row1["first"]; $last= $row1["last"]; $date= $row1["date"]; $email=$row1['email']; $tos[]= new To( "$email", "$first $last", [ '{{First_Name}}' => $first, '{{Last_Name}}' => $last, '{{testing}}' => $date, '{{email}}' => $email, ], "View your Testing Report Card!" ); } } $globalSubstitutions = [ '-time-' => "2018-05-03 23:10:29" ]; $plainTextContent = new PlainTextContent( "Good Morning!<br> <br> {{First_Name}}'s report card from the {{testing}} testing is ready to view.<br> <br> Please click the link below to view. <br> <br>Login with the following:<br> Name: {{First_Name}}<br> Email: {{email}}.<br> <br> " ); $htmlContent = new HtmlContent( "Good Morning!<br> <br> {{First_Name}}'s report card from the {{testing}} testing is ready to view.<br> <br> Please click the link below to view. <br> <br>Login with the following:<br> Name: {{First_Name}}<br> Email: {{email}}.<br> <br> " ); $sendgrid = new \SendGrid('apikey'); try { $response = $sendgrid->client->mail()->batch()->post(); print $response->statusCode() . "\n"; print_r($response->headers()); $batch= $response->body() . "\n"; echo $batch."<br> <br> <br> "; } catch (Exception $ex) { echo 'Caught exception: '. $ex->getMessage(); } $data = json_decode($batch); $batchnew= $data->batch_id; $sendtime=strtotime("today 9:02"); $email = new Mail( $from, $tos, $subject, // or array of subjects, these take precedence $plainTextContent, $htmlContent, $globalSubstitutions ); $email->setSendAt($sendtime); $email->setBatchId($batchnew); try { $response = $sendgrid->send($email); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; } catch (Exception $e) { echo 'Caught exception: '. $e->getMessage(). "\n"; } I edited the code to not include personal information. As you can see, I run a loop at the start to create an array of data for the to addresses. This sends multiple emails (not just one email with multiple to's). However, no matter what I put in the for sendat time, it sends it right away when there is more than one email present. I tried creating a batch id then getting the id via json and then setting the batch id, but it still sends right away. Any help would be appreciated!
  2. I am trying to run two queries within one I guess you could say. What I am trying to do is build a scoring system where each person gets two chances. The least number is their best. What I need to have happen is for the php query to select the smallest number for each person, then display the 3 names of the people with the 3 smallest numbers. I am guessing I need to use a query like this to get the smallest number for each person: $sql = mysql_query("SELECT LEAST(MIN(COL1),MIN(COL2))FROM yourtable;"); but after this I am stumped as to how to make it display the names associated with the 3 smallest numbers. Can anyone help me out?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.