0

I am using SparkPost PHP API for sending emails and it seems like reply_to feature is not working. I tried to both ways with headers and with reply_to field. Any ideas what could be wrong? Domain name of reply_to emails is different as senders one. I didn't found any restrictions regarding this in their documentation. Any ideas?

Here is my code:

     $emailData = array(
        'from'=> $data["from_name"].' <'.$data["from_email"].'>',
        'html'=> $data["html"],
        'inline_css' => true,
        'transactional' => true,
        'subject'=> $data["subject"],
        'recipients'=> $rec["r"]
    );

    if(isset($data["headers"]["Reply-To"]))
        $emailData['reply_to'] = $data["headers"]["Reply-To"];


    try {
        // Build your email and send it!
        $this->mandrill->transmission->send($emailData);
    } catch (\Exception $err) {
        echo "<pre>";
        print_r($err);
        echo "</pre>";
    }
Grokify
  • 15,092
  • 6
  • 60
  • 81
Smuk3c
  • 132
  • 7
  • Could you please correct the spelling of your title to SparkPost? I had a really hard time finding a solution to this question. – DeFeNdog May 04 '17 at 16:13

2 Answers2

3

Regarding: SparkPost PHP ReplyTo, reply_to, Reply

For anyone else wondering the same thing. Here's my implementation using SparkPost client library for PHP v2.1. I hope it helps.

I used the transmissions endpoint as seen in the docs.

https://github.com/sparkpost/php-sparkpost

$promise = $sparky->transmissions->post([
  'content' => [
      'from' => [
          'name' => 'Company Name',
          'email' => 'noreply@company.com',
      ],
      'reply_to' => $email,
      'subject' => 'Some Subject',
      'html'    => $html_message,
      'text'    => $text_message,
  ],
  'substitution_data' => $subData,
  'recipients' => [

    [
      'address' => [
        'name' => 'My Recipient',
        'email' => 'me@company.com',
      ]
    ],

  ],

]);
Grokify
  • 15,092
  • 6
  • 60
  • 81
DeFeNdog
  • 1,156
  • 1
  • 12
  • 25
  • This should be accepted answer. For more user friendly you can take a format [SOME_NAME] <[some_email]>. So example would be: 'reply_to' => "Foo Name ", – Danijel Aug 17 '17 at 13:23
  • Works perfect, I needed the 'reply_to' => $email, and it works! thanks – Junaid Anwar Oct 05 '17 at 21:37
2

Thank god for slack :)

Solution is that SparkPost has different name for parameters in API documentation. Correct parameter for PHP API is not reply_to (as it's written in doc) but replyTo.

Grokify
  • 15,092
  • 6
  • 60
  • 81
Smuk3c
  • 132
  • 7