Send email using PHP SDK

(Timothy Jensen) #1

I’m wondering why this returns false?


$contact_id = $infusionsoft->contacts( 'xml' )->addWithDupCheck( $contact, 'Email' );

$response = $infusionsoft->emails( 'xml' )->sendEmail( [ $contact_id ], '', 
$user->data->user_email, '', '', 'HTML', 'Message Subject', "HTML content", "Text content" );

// I'm getting a valid email, Infusionsoft contact ID, but the email response is `false`
var_dump( $user->data->user_email, $contact_id, $response );

(John Borelli) #2

Have you tried to do this with a template id as well?

(Timothy Jensen) #3

No, not yet. I’ll give that a try tomorrow and report back. Thanks.

(Timothy Jensen) #4

I added a template ID '145', and tried both Text, and HTML content types. Still no luck.

(Jon Smith) #5

Is the email address in a marketable status inside of Infusionsoft?

(Timothy Jensen) #6

That was it, Jon! I’m trying to send the contact an email after they submit a form, so I guess I need to opt-in the contact via the API then send the e-mail.

(Jon Smith) #7

Correct the flow in this instance would be

  • Add Contact
  • Opt in Email
  • Send email

(Igor Santos) #8

Needless to mention that a plain false with no explanation, exception or notice is really bad for developer experience, right? There’s no mention about that on the API docs as well. I had to dig around to discover this - and even when the email arrives in my inbox it still returns false :thinking:

(Jon Smith) #9

Boolean logic. It is either true or false. If one email isn’t marketable then it will return false since it wasn’t a 100% success.

(John Borelli) #10

False will be the response if an optin cannot happen due to one of two reasons:

  1. The optin is attempted on an email address that is already opted out OR
  2. When the status is already opted in (ie you can’t optin an address that is already opted in).

True will only return if a status is not yet opted in when optin is called.