I already created a workflow and it sends the desired opt-in mail, but the problem is, that the value of “confirm_opt_in_token” is not calculated, e.g. empty.
I see. In fact, sending an opt-in email is not as simple as sending a generic email. Some extra processing is required, and it’s not happening when sent from a Workflow.
Maybe your only chance is to use a Logic hook instead of a Workflow, and inside that hook do the rest of the work (create token etc) by copying it from some other place in the code where that is already done. With luck, you only have to call a function and it will do everything for you.
I am not sure where that might be. Try a few searches in the code, you might find it.
we solved this for leads with a custom entrypoint. The confirm_opt_in_token is not calculated when created by api/web.
Our leads are created by WordPress in SuiteCRM, there we have a workflow defined when lead is saved which sends the confirm optin mail. The mail includes a link to a custom entrypoint with it’s lead id.
If you want you can get the code for this and modify it for contacts.
The other solution could be using a workflow which triggers at saving e-mail addresses.
when confirm_opt_in_token isnull then calculate it with suitecrm formula (copied from SugarEmailAddress.php):
// FILE: custom/modules/Leads/LeadsOptin.php
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
global $timedate;
/**
* Entrypoint for OptIn
* Author: Rolf RiethmĂĽller / Dipesh Patel
* (c) itons GmbH
* do not sell anywhere
*
* custom fields for Leads
* - optin: bool, set by entrypoint, indicates if optin is done
* - optin_url: varchar, set by workflow, this is the url to use in E-Mail template for optin
* ( https://<your suitecrm site>/index.php?entryPoint=LeadsOptin)
* - optin_dt: datetime, set by entrypoint, datetime when optin is done
* - optedin_url: varchar, set by workflow, is used to call page on website to say thanks for optin
* - lead_stage:enum, not neccessary, is used for our sales pipe
*/
$oeplFlg = TRUE;
$RetMsg= '';
$OptinID = trim( $_REQUEST['eid'] );
if(empty($OptinID))
{
//die('Unauthorized access.');
$oeplFlg = FALSE;
$RetMsg = 'Optin: access denied';
}
$objLead = BeanFactory::getBean('Leads');
$objLead->retrieve( $OptinID );
if(empty($objLead->id))
{
$oeplFlg = FALSE;
$RetMsg = 'Optin: Lead-ID not found:' . $OptinID;
}
if($objLead->optin == '1')
{
$oeplFlg = FALSE;
}
if($oeplFlg == TRUE)
{
$objLead->optin_dt = $timedate->nowDb();
$objLead->lead_stage = 'optin';
$objLead->optin = '1';
$objLead->processed = true; // Restrict to call logic hook during save record
$objLead->save();
} // End of Lead save IF conditions
if( empty($objLead->optin_url) ) {
$URL_OptedIn= '' ; //put here url after optin to say thanks
}
else {
$URL_OptedIn= $objLead->optin_url;
}
if (!preg_match("~^(?:f|ht)tps?://~i", $URL_OptedIn)) {
$URL_OptedIn = "https://" . $URL_OptedIn;
}
header('location: ' . $URL_OptedIn);
exit;
?>