Send email using PHP SDK

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 );

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

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

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

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

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.

Correct the flow in this instance would be

  • Add Contact
  • Opt in Email
  • Send email

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:

1 Like

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.

1 Like

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.