Rectangle 27 0

At present there's no way request to lookup specific events by unique_arg with the Web API.

However, the SendGrid Event Webhook will give you granular data on each event, such as a bounce as it happens. The Event Webhook POSTs data to your server every time an action is taken upon an email (e.g. open, click, bounce).

Once you receive it, you're responsible for storing this, although it's not a typical API it gives very specific data on events which you can then compile and rehash however you like.

To get started using the webhook, you'll do something like the following, and have SendGrid POST to the following script:

<?php
$data = file_get_contents("php://input");
$events = json_decode($data, true);

foreach ($events as $event) {
  // Here, you now have each event and can process them how you like
  process_event($event);
}

php - SendGrid Web API bounced email header response - Stack Overflow

php api sendgrid
Rectangle 27 0

Without more info about how you're actually sending the email (web?, smtp?, libraries?, etc), it's hard to give you a concise answer. That said, one of these three options should work:

1) If you're sending over HTTP with the web API

You can actually just add two extra parameters to your POST body, fromname and replyto, and send them along with the normal to, from, subject, etc.

2) If you're sending over SMTP with the PHP library

The PHP helper library (found here) has two helper methods, setReplyTo and setFromName to help you with that.

$mail = new SendGrid\Mail();
$mail->addTo('foo@bar.com')->
     setReplyTo('someone.else@example.com')->
     setFromName('John Doe')->
     ...

3) If you're sending with SwiftMailer

SwiftMailer is a popular SMTP library for PHP. It has it's own helper methods from Reply to and From name. You can find more info in the docs (see setReplyTo and setFrom)

Thanks a lot once again! I do have another issue though. If the message is send to multiple recipients(addTo in a foreach loop), do I need to set the replyTo, and the fromName per each recipient individually, or just once at the end. And also, why when I try to add a bcc for each mail t hat is sent out by SendGrid for testing purposes, the entire list of me recipients gets disclosed

There's a lot of questions in your comment. Mind contacting our support team (support.sendgrid.com) or opening up a new question?

How to add a reply-to and a from-name header with SendGrid php library...

php sendgrid
Rectangle 27 0

From the raw data it looks like you are specifying the recipients in the SMTP message as well as in the X-SMTPAPI header. You want to specify them only in the X-SMTPAPI header. If you post the code that is generating the SMTP message I can help identify where the problem might be.

Hey Brand, I appreciate the help. I will provide my code after I give it a try. According to sendgrid, there is 2 methods to send to recipients. One is in the message, the other is using the To in the header. your saying in order for this to work. the To must be specified within the header

The second attempt looks closer. Posting the exception that you are getting now should help a lot. It could very well be that your X-SMTPAPI header line is too long and needs to be wrapped. Take a look at the generic PHP SMTP API Header code for an example on how to wrap it so the lines are RFC compliant: sendgrid.com/docs/Code%20Examples/

php - SendGrid X-SMTPAPI is being ignored in my header request file be...

php api cakephp rest sendgrid
Rectangle 27 0

Sorry to hear you've been running into trouble with the SMTPAPI and that support wasn't able to assist you. You're probably right about hitting the 1000 character limit. Depending what you're sending the email with, you might be able to add in some indenting space to solve the problem:

var SMTPAPIHeader = JSON.stringify(yourJSONobject, null, " ");

Also, feel free to email community@sendgrid.com if you'd like some more help from our developer relations team.

Problem is that I am using it in t he PHP cli environment. Any alternatives to this there?. The support guys just told me to add "\r\n", which I already did, and yet when I output the headers using $mail->getHeadersJson(), in sublime it seems as if the whole header consists only of one - several lines.

php - Invalid SMTPAPI Header - SendGrid - Stack Overflow

php sendgrid
Rectangle 27 0

I found the solution. section is used after substitution and perform on what sub does. So if I wanted to use %postname% in all emails first I must make sure that sub will place %postname% somewhere in the content.

php - Using section header in Sendgrid - Stack Overflow

php sendgrid