How to send variables like {contactfield=id} in MAUTIC email campaign? - php

I want to send {contactfield=id} (one of the variable of the mautic) into custom headers for a mail that is to be used for a campaign. I am not sure of the right way to send it. I am keeping this variable into custom headers under Channels > Emails and selecting a particular email's advanced settings and into custom headers. This sets the id value of the first contact in the contact list of the segment selected for the campaign into all the remaining contacts. I want to get the dynamic value of each contact's id respectively. How can I get this appropriate result? Thanks in advance.

Last time I checked, not all of the fields in the Email builder can contain tokens. I remember that the Body and Subject allow it, but there were some other fields that did not allow it.
You seem to be getting the correct token, so if it's not returning in the header based on your testing, that field may not get parsed for tokenization on processing.

As pointed out by Jordan Ryan, not all tokens are available under email, however the email object can be tapped by creating a custom plugin.
https://developer.mautic.org/#extending-emails
check out this section, it may help.
The second example on code block shows that you can place your custom placeholder and then replace it programmatically.
/**
* Search and replace tokens with content
*
* #param EmailSendEvent $event
*/
public function onEmailGenerate(EmailSendEvent $event)
{
// Get content
$content = $event->getContent();
// Search and replace tokens
$content = str_replace('{hello}', 'world!', $content);
// Set updated content
$event->setContent($content);
}

Related

Using Advanced Custom Field value as "Email to" in Contact Form 7

I'm creating a page in which you submit a Contact Form 7 to the email based on what email is added to the job_email field via my Advanced Custom Fields.
I have attempted to add the form via the PHP shortcode like this
[email* dynamic-email class:email-address placeholder "Email Address*"]
echo do_shortcode('[contact-form-7 id="234" title="Dynamic Submit CV" dynamic-email="'.get_field( 'job_email' ).'"]' );
The fields all display correctly, and upon submitting the email successfully, the email never receives the form. Meaning I am totally missing something here.
If I understand correctly, what you are after is send a notification with the entry details to the email address inputted on the job_email field.
If so, what you want to do is to set up an email on the email tab and in the To: setting put [job_email].
Update
As you stated in the comment, the email has to be the one set in the backend. You can guarantee the email notification to be sent to the ACF-based email via hooks, specifically the wpcf7_mail_components hook.
function so57013385_mail_components( $components, $number ) {
$job_mail = get_field( ... );
$components['recipient'] = (array) $components['recipient'];
$components['recipient'][] = $job_mail;
return $components;
};
add_filter( 'wpcf7_mail_components', 'so57013385_mail_components', 10, 2 );
Note: I'm casting the $components['recipient'] variable to array just to make sure the email is appended correctly, as this parameter is passed directly to wp_mail(), which can receive a string or an array. Also, you might need to add more validations on the form ID, sanitization, etc. The above code is not tested.

How to enumerate the forms in cf7?

I'm a newbie to web designing. I'm using contact form 7 to create a registration form for our conference.
All I wanted to do is, I need to give a unique id for all of them after they have registered for the conference and the further forms should be identified using this unique id.
So far, I have installed contact form 7 and contact form dtx
for this purpose and I have tried Koen de Bakker solution of generating a random number.
But it's slightly different from what I want, since it changes the random number for each refresh.
What I'd like is:
An unique number like "17ICLAA001,..." should be generated for each form submission.
Send the unique number to the applicant after successive submission of the form.(I hope this can be easily done once the shortcode is done).
Editing the form using the unique id.
Any help will be much appreciated. Thank you.
I have found a way to do this. Its just the number of rows+1 in the table.
When you add a record to your table the unique number also gets increased by 1 in the following code. Add the following function in function.php in your theme and use the short code "row_count" to call the function. Use it with dynamichidden text from dtx.
function row_count_shortcode() {
global $wpdb;
$user_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->username_wp1.SaveContactForm7_1" )+1;
return "17ICLAA".sprintf('%03d',$user_count);
}
add_shortcode( 'row_count', 'row_count_shortcode' );
Usually when you are creating contact forms using contact form7 it automatically creates a table in your database something like
username_wp1.SaveContactForm7_1
Instead of this replace your database table name.
So in your contact form, type
[dynamichidden uniqueid "row_count"]
and use [uniqueid] in your email body to serve your purpose.
It works fine. I have checked in my site.
Correct way to generate a unique and progressive number is to set a field in wp_option like this:
add_option('unique_number', '1');
When filter is called, you must simply increment this unique number:
function genTicketString() {
$currentUniqueNumber = get_option('unique_number');
$newCurrentUniqueNumber = $currentUniqueNumber + 1;
update_option('unique_number' $newCurrentUniqueNumber );
return $newCurrentUniqueNumber;
}
add_shortcode('quoteticket', 'genTicketString');

Docusign api php add signer on the fly to template

when i add new recepient and sent the document in template using below code
$templateRole = new \DocuSign\eSign\Model\TemplateRole();
$templateRole->setEmail("user#email.com");
$templateRole->setName("User Name");
$templateRole->setRoleName("Admin");
I use Docusign Php Client, you can find the whole code below I used for this on that page.
Here it send the email containing document to user#email.com, but user#email.com's user is not able to sign that document.
I've also added the dynamic text to the document in the template.Added one signer recipient to template (because i was not able to add the dynamic labels without it), this user get all the emails even i don't specify him on the above code.
I want something like to send a document in template to different recepients (like user1#gmail.com, user2#gmail.com etc) one at a time (they may or may not have docusign account, though is it possible if they have docusign account?)
I am doing this since 4 days, not finding anything about proceeding furthur, please help.
I have read some of the documentation. As far as I can see you should do the following:
//first signer
$templateRole1 = new \DocuSign\eSign\Model\TemplateRole();
$templateRole1->setEmail("user1#email.com");
$templateRole1->setName("User1 Name");
$templateRole1->setRoleName("Admin");
//second singer
$templateRole2 = new \DocuSign\eSign\Model\TemplateRole();
$templateRole2->setEmail("user2#email.com");
$templateRole2->setName("User2 Name");
$templateRole2->setRoleName("Admin");
And then in the envelop:
$envelop_definition->setTemplateRoles(array($templateRole1, $templateRole2));

Create and use tokens in texarea to add templates

I am working on a project where I need to add a email template that uses variables for name, address and phone number.
In my database i have 2 tables
Users - with name, address, phone number and category
Email_templates - for different email templates like Christmas, New year etc
on front end i have a textarea to add templates in database.
My template contains tokens like {name}, {address}, {phone} that are replaced with respective user detail when I send emails using that template.
Now i am able to fetch all details for users and email templates but not able to replace the tokens with values with php.
i tried str_replace to replace {name} and other tokens with variables like $user->name.
You can use below code to replace tokens :
$template_body = file_get_contents('Email template file path');
$email_values= array(
'name'=>$user->name,
'address'=>$user->address,
'phone'=>$user->phone,
);
if(count($email_values)>0)
{
foreach($email_values as $key=>$value)
{
$template_body = str_replace('{'.$key.'}',$value,$template_body);
}
}
return $template_body;

Drupal 6 - Content profile fields within page-user.tpl.php

Going a bit mad here... :)
I'm just trying to add CCK fields from a Content Profile content type into page-user.tpl.php (I'm creating a highly-themed user profile page).
There seem to be two methods, both of which have a unique disadvantage that I can't seem to overcome:
'$content profile' method.
$var = $content_profile->get_variables('profile');
print $var['field_last_name'][0]['safe'];
This is great, except I can't seem to pass the currently viewed user into $content_profile, and it therefore always shows the logged in user.
'$content profile load' method.
$account_id = arg(1);
$account = user_load($account_id);
$user_id = $account->uid;
$var = content_profile_load('profile', $user_id);
print $var->field_first_name[0]['value'];
Fine, but now I can't access the full rendered fields, only the plain values (i.e. if the field has paragraphs they won't show up).
How can I have both things at once? In other words how can I show fields relating to the currently viewed user that are also rendered (the 'safe' format in 1)?
I've Googled and Googled and I just end up going round in circles. :(
Cheers,
James
Your content profile load method seems to be the closest to what you want.
In your example:
$account_id = arg(1);
$account = user_load($account_id);
$user_id = $account->uid;
$var = content_profile_load('profile', $user_id);
print $var->field_first_name[0]['value'];
The $var is just a node object. You can get the "full rendered fields" in a number of ways (assuming you mean your field with a filter applied).
The most important thing to check is that you're field is actually configured properly.
Go to:
admin/content/node-type/[node-type]/fields/field_[field-name] to configure your field and make sure that under text processing that you've got "Filtered text" selected.
If that doesn't fix it,try applying this:
content_view_field(content_fields("field_last_name"), $var, FALSE, FALSE)
(more info on this here: http://www.trevorsimonton.com/blog/cck-field-render-node-formatter-format-output-print-echo )
in place of this:
print $var->field_first_name[0]['value'];
if none of that helps... try out some of the things i've got on my blog about this very problem:
http://www.trevorsimonton.com/blog/print-filtered-text-body-input-format-text-processing-node-template-field-php-drupal
When you're creating a user profile page there is a built in mechanism for it. just create a user template file, user_profile.tpl.php.
When you use the built in mechanism you automatically get access to the $account object of the user you are browsing, including all user profile cck fields. You have the fields you are looking for without having to programmatically load the user.
I have a field called profile_bio and am able to spit out any mark up that is in without ever having to ask for the $account.
<?php if ($account->content[Profile][profile_bio]['#value']) print "<h3>Bio</h3>".$account->content[Profile][profile_bio]['#value']; ?>
I've tried themeing content profiles by displaying profile node fields through the userpage before and it always seems a little "hacky" to me. What I've grown quite fond of is simply going to the content profile settings page for that node type and setting the display to "Display the full content". This is fine and dandy except for the stupid markup like the node type name that content profile injects.
a solution for that is to add a preprocess function for the content profile template. one that will unset the $title and remove the node-type name that appears on the profile normally.
function mymodule_preprocess_content_profile_display_view(&$variables) {
if ($variables['type'] == 'nodetypename') {
unset($variables['title']);
}
}
A function similar to this should do the trick. Now to theme user profiles you can simply theme your profile nodes as normal.

Categories