Welcome Message not being sent using API

Occasional Participant

Welcome Message not being sent using API

I am essentially using this code here:




Except I added a 3rd parameter for 'action_by' = 'ACTION_BY_VISITOR'


I have two emails I am trying. One that's already in the system, and a new one. The one that's already in the system I can't update to change 'ACTION_BY_OWNER' to 'ACTION_BY_VISITOR'. When adding a new email, the response shows 'ACTION_BY_VISITOR' but the email still isn't being sent. What am I am missing?


$optParams = array('action_by' => 'ACTION_BY_VISITOR');

	    if (isset($list) && isset($email) && strlen($email) > 1) {
	        try {
	            // check to see if a contact with the email address already exists in the account
	            $response = $cc->contactService->getContacts(ACCESS_TOKEN, array("email" => $email));
	            $contact = $response->results[0];

	            // create a new contact if one does not exist
	            if (empty($response->results)) {
	                $contact = new Contact();
	                $contact->first_name = $firstName;
	                $contact->last_name = $lastName;

	                $returnContact = $cc->contactService->addContact(ACCESS_TOKEN, $contact, $optParams);
	            } else {
	                //updating contact (adding to new list)
	                $contact = $response->results[0];
	                if ($contact instanceof Contact) {
	                	$returnContact = $cc->contactService->updateContact(ACCESS_TOKEN, $contact, $optParams);
	        } catch(CtctException $ex) {
	            foreach ($ex->getErrors() as $error) {
	            $msg['success'] = false;
	            $msg['msg'] = 'Error Subscribing';
Frequent Participant

I just went through something similar and found that the email only sends for brand new contact. If the contact had been added and then deleted, the email wouldn't send (I tested a lot with the same email address). The other thing is to ensure that Confirmed Opt-in is turned on under your account settings.


I don't know if either of these fit your case but I figured I'd pass them along.

Occasional Participant

Thanks for the note. I turned on Confirmed Opt In, and got an email to confirm I wanted to subscribe, once I clicked that, I got the welcome email. Is there any way to make it so when a user signs up on our site and we subscribe them via API, to bypass the confirmation and automatically deliver the welcome email?


Here is the response object from signing up a new email address using the code from the original post.


$returnContact = Ctct\Components\Contacts\Contact[21]
	$returnContact->id = (string) <REDACTED>
	$returnContact->status = (string) UNCONFIRMED
	$returnContact->first_name = (string) aaaa
	$returnContact->last_name = <string>
	$returnContact->confirmed = (bool) 0
	$returnContact->source = (string) API
	$returnContact->email_addresses = array[1]
		$returnContact->email_addresses[0] = Ctct\Components\Contacts\EmailAddress[7]
			$returnContact->email_addresses[0]->id = (string) <REDACTED>
			$returnContact->email_addresses[0]->status = (string) UNCONFIRMED
			$returnContact->email_addresses[0]->confirm_status = (string) UNCONFIRMED
			$returnContact->email_addresses[0]->opt_in_source = <null>
			$returnContact->email_addresses[0]->opt_in_date = <null>
			$returnContact->email_addresses[0]->opt_out_date = <null>
			$returnContact->email_addresses[0]->email_address = (string) <REDACTED>
	$returnContact->prefix_name = <string>
	$returnContact->job_title = <string>
	$returnContact->addresses = array[0]
	$returnContact->notes = array[0]
	$returnContact->company_name = <string>
	$returnContact->home_phone = <string>
	$returnContact->work_phone = <string>
	$returnContact->cell_phone = <string>
	$returnContact->fax = <string>
	$returnContact->custom_fields = array[0]
	$returnContact->lists = array[1]
		$returnContact->lists[0] = Ctct\Components\Contacts\ContactList[6]
			$returnContact->lists[0]->id = (string) <REDACTED>
			$returnContact->lists[0]->name = <null>
			$returnContact->lists[0]->status = (string) ACTIVE
			$returnContact->lists[0]->contact_count = <null>
			$returnContact->lists[0]->created_date = <null>
			$returnContact->lists[0]->modified_date = <null>
	$returnContact->created_date = (string) 2015-09-04T13:44:36.000Z
	$returnContact->modified_date = (string) 2015-09-04T13:44:36.000Z
	$returnContact->source_details = (string) Website



You're very close to what you're looking to accomplish. While it is required that it be a new email address that has not been used before to receive a welcome email, Confirmed Opt-in is not a requirement for that. The key to this code is that even if you delete a contact, it is a soft-delete and this sample will find the deleted contact and restore it. This process will not result in a welcome email being sent, unless that contact was also opted-out. For contacts that are opted out, they will receive an email to confirm that they wish to resubscribe, which will be followed by a welcome email if they confirm the resubscription.


Your current process should continue to work fine if you simply disable confirmed opt-in. If you see results that are different from that, please let me know!



Elijah G.
API Support Engineer
Developer Portal

View API documentation, code samples, get your API key.

Visit Page