send HTML markup from Custom Field to the Email Campaign - php

I have an E-commerce website and is integrated to InfusionSoft
What currently happening is that...
Customer completes an order on my website and purchases, let say 2 products.
Upon Order Completion, Order Received tag is added and customer's info is added to InfusionSoft, and the Order Detail HTML Markup (which is generated on my website via code) is added to a Custom Field, ~_myCustomField~
There is already a campaign running which send simple Thank You Email to customer.
What I want is that I can send the Order Detail(which is stored in ~_myCustomField~) along with the Thank You Email
What I have tried that, I have added the custom field into Campaign's Email just like ~Contact._myCustomField~ but it sends the only HTML, not generated one!
_myCustomField contains for example
<table>
<tr>
<td>This is your order detail</td>
</tr>
</table>

Instead of saving the HTML into a custom field, you can just send the thank you email at that point.
You can use the email service to send an email:
https://developer.infusionsoft.com/docs/read/Email_Service
example:
$title = "template API test";
$category = "API Category";
$fromAddress = "from#infusionsoft.com";
$toAddress = "~Contact.Email~";
$ccAddress = "";
$bccAddresses = "";
$subject = "My Fancy Subject Line";
$textBody = "This is the text email body";
$htmlBody = "HTML"
$contentType = "Contact";
$mergeContext = "";
$tmpId = $app->addEmailTemplate($title, $category, $fromAddress, $toAddress, $ccAddress, $bccAddresses, $subject, $textBody, $htmlBody, $contentType, $mergeContext);
If you want to keep the interaction with the campaign, you can use the goal feature. Learn more about goals here.
You will be after the funnel service to see if a goal has been completed (such as an order) and send the Thank you email at that point.

Related

PHP : Read GMAIL Email with imap

here's my problem: I have a mailbox where came from 2 types of email:
1) e-mail with plain text
2) email, I think, base64-encoded text / html
I have a simple page in php that goes to read this email box, and prints out an HTML table with some information of each email
I recognize the two types of email from the object of the email, in the first case I have no problems, while in the second i have a problem
i read the "body" of the mail of the first type in this way (and I have no problem, I can print the contents of the email as plain text) :
$id = imap_uid($stream ,$email_id);
$message = imap_qprint(imap_body($stream, $email_id,FT_PEEK));
but in the second case it does not work this way, and I have tried the following
$message = imap_fetchbody($stream,$email_id,"");
$message = imap_fetchbody($stream,$email_id,"0");
$message = imap_fetchbody($stream,$email_id,"1");
$message = imap_fetchbody($stream,$email_id,"1.1");
$message = imap_fetchbody($stream,$email_id,"1.2");
$message = imap_fetchbody($stream,$email_id,"2");
echo "*".base64_decode($message)."*";
echo "*".imap_base64($message)."*";
but I have no result

wordpress contact form 7 to sync to mailchimp list using api

I am trying to send contact form 7 data to mailchimp list. So far this works well following this tutorial http://www.limecanvas.com/a-mailchimp-opt-in-field-for-contact-form-7/
I am trying to modify the php to collect a telephone number and post that as a merge tag into the mailchimp list.
function wpcf7_send_to_mailchimp($cfdata) {
$formtitle = $cfdata->title;
$formdata = $cfdata->posted_data;
// Opt-in field checked?
if ( $formdata['mailchimp-optin'] ) {
$names = explode(' ',trim($formdata['first-name']));
$firstName = $names[0];
$lastName = '';
if (count($names)>1){
// more than one word in name field
$lastName = array_pop($names);
}
$send_this_email = $formdata['your-email'];
$mergeVars = array(
'FNAME'=>$firstName,
'LNAME'=>$lastName
);
// MCAPI.class.php needs to be in theme/includes folder
require_once('core/includes/MCAPI.class.php');
// grab an API Key from http://admin.mailchimp.com/account/api/
$api = new MCAPI('apikey');
// grab your List's Unique Id by going to http://admin.mailchimp.com/lists/
// Click the "settings" link for the list - the Unique Id is at the bottom of that page.
$list_id = 'listid';
// Send the form content to MailChimp List without double opt-in
$retval = $api->listSubscribe($list_id, $send_this_email, $mergeVars, 'html', false,true);
}
}
add_action('wpcf7_mail_sent', 'wpcf7_send_to_mailchimp', 1);
I have setup the form field in mailchimp and am trying this:
$telephone = $formdata['you-tell'];
and adding the merge tag to the mergetag array:
'TELL'=>$telephone
I am not a php guy (more comfortable with jquery) so I might be approaching this wrong?
essentially I need to extract the data from contact form 7 and add to the mailchimp mergetag array.
Thanks for the pointers
MailChimp for WordPress does just that. It uses the MailChimp API in combination with the WordPress HTTP API which makes it less error prone.
The following Contact Form 7 template will feed the entered values to your MailChimp list.
[text* mc4wp-FNAME]
[text* mc4wp-LNAME]
[tel mc4wp-TELL]
[mc4wp_checkbox "Sign-up to our newsletter."]
Hope that helps!
ok, Figured it out... really simple:
$tell = $formdata['your-tell'];
$mergeVars = array(
'FNAME'=>$firstName,
'LNAME'=>$lastName,
'TELL'=>$tell
);
Ammended these lines

Get Contents from Text File and Replace Keywords PHP

I have a form. I'm using "post" method that sends and emails to multiple people that registered. Then the $body of the email is based on a template. No database, no classes, simple form. Yes I read up about this already they're all there I just couldn't put it together, related to this case.
The text "email_template.txt" should have something like:
Hello #firstname# #lastname#. Thank you for registering! Your registered email is #email#
Would look like this upon processing by PHP
Hello **John Doe**. Thank you registering! Your registered email is **example#example.com**.
On my php I have something like:
<?php
//form and validation
$firstname = "John"; // inputed name on the form, let say
$lastname = "Doe"; // inputed last name
$email = "example"; // inputed email
//email message
$body = ... some type of a get_file_content....
mail($_POST['email'], 'Party Invitation', $body, 'From: admin#admin.com');
?>
Where $body is the email message to the registrants submitted via this PHP form.
sprintf will work good
your template could be:
Hello %s %s. Thank you for registering! Your registered email is %s
$body = sprintf($fileContents,$firstname,$lastname,$email);
or str_replace(), pretty much a find replace.
$body = "Hello #firstname# #lastname#. Thank you for registering! Your registered email is #email#";
$body = str_replace("#firstname#",$firstname,$body);
$body = str_replace("#lastname#",$lastname,$body);
$body = str_replace("#email#",$email,$body);

How can I add HTML formatting to 'Swift Mail tutorial based' PHP email?

I have developed a competition page for a client, and they wish for the email the customer receives be more than simply text. The tutorial I used only provided simple text, within the 'send body message'. I am required to add html to thank the customer for entering, with introducing images to this email.
The code is:
//send the welcome letter
function send_email($info){
//format each email
$body = format_email($info,'html');
$body_plain_txt = format_email($info,'txt');
//setup the mailer
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance();
$message ->setSubject('Thanks for entering the competition');
$message ->setFrom(array('info#examplemail.com' => 'FromEmailExample'));
$message ->setTo(array($info['email'] => $info['name']));
$message ->setBody('Thanks for entering the competition, we will be in touch if you are a lucky winner.');
$result = $mailer->send($message);
return $result;
}
This function.php sheet is working and the customer is recieving their email ok, I just need to change the
('Thanks for entering the competition,
we will be in touch if you are a lucky
winner.')
to have HTML instead...
Please, if you can, provide me with an example of how I can integrate HTML into this function.
You can also just add 'text/html' to setBody (ref):
->setBody($this->renderView('YouBundleName:Default:email.html.twig'), 'text/html');
$message = Swift_Message::newInstance();
$message->setContentType('text=html');
Will the same text remain or should it be styled somehow?
Editing your emails in html requires inline css styles eg:
('<p style="font-size:1.2em; color:#f0f0f0;">Thanks for entering the competition, we will be in touch if you are a lucky winner.</p>')
if you need a table just add:
('<table style="font-size:1.2em; color:#f0f0f0;"><tr><td>Thanks for entering the competition, we will be in touch if you are a lucky winner.</td></tr></table>')
or to make it more simpler
$message_body'
<table style="font-size:1.2em; color:#f0f0f0;">
<tr>
<td>Thanks for entering the competition, we will be in touch if you are a lucky winner.</td>
</tr>
</table>
';
$message ->setBody($message_body);
I know that when I need to send html emails I need to set the content-type to html which I believe you did on the following line
$body = format_email($info,'html');
I hope this is what you were looking for. if not let me know

What is the best way to use Email Template in Zend/PHP

I am working on a website where Users create their accounts. I need to send email to users on many oceans. For example when signup, forgot password, order summary etc. I want to use emails templates for this. I need your suggestions for this. I want to use a way that If I change any email template or login in less time and changes.
I have thought about the following way:
I have a table for email templates like this:
id
emailSubject
emailBody
emailType
For example when user forgot password:
id:
1
emailSubject:
ABC: Link for Password Change
emailBody:
<table border=0>
<tr><td>
<b> Dear [[username]] <b/>
</td></tr>
<tr><td>
This email is sent to you in response of your password recovery request. If you want to change your password, please click the following link:<br />
[[link1]]
<br/>
If you don't want to change your password then click the following link:<br/>
[[link2]]
</tr></td>
<tr><td>
<b>ABC Team</b>
</td></tr>
</table>
emailType:
ForgotPassword
Prepare email data:
$emailFields["to"] = "user#abc.com";
$emailFields["username"] = "XYZ";
$emailFields["link1"] = "http://abc.com/changepassword?code='123'";
$emailFields["link2"] = "http://abc.com/ignorechangepasswordreq?code='123'";
$emailFields["emailTemplate"] = "ForgotPassword";
Now Pass the all fields to this function to send email:
sendEmail( $emailFields ){
// Get email template from database using emailTemplate name.
// Replace all required fields(username, link1,link2) in body.
// set to,subject,body
// send email using zend or php
}
I planed to use above method. Can you suggest better way or some change in above logic.
Thanks.
I'd use Zend_View. Store your templates in /views/email/EMAILNAME.phtml, create a Zend_View object with the required email template and pass it the required data.
Off the top of my head, so untested... but something similar should work:
$view = new Zend_View();
$view->setScriptPath( '/path/to/your/email/templates' );
$view->assign( $yourArrayOfEmailTemplateVariables );
$mail = new Zend_Mail();
// maybe leave out phtml extension here, not sure
$mail->setBodyHtml( $view->render( 'yourHtmlTemplate.phtml' ) );
$mail->setBodyText( $view->render( 'yourTextTemplate.phtml' ) );
As previously mentioned, Zend_View is the way. Here is how I do this:
$template = clone($this->view);
$template->variable = $value;
$template->myObject = (object)$array;
// ...
$html = $template->render('/path/filename.phtml');
Use Markdownify to covert to plain text:
$converter = new Markdownify_Extra;
$text = $converter->parserString($html);
Setup mail:
$mail = new Zend_Mail();
$mail->setBodyHtml($html);
$mail->setBodyText($text);
Then setup Transport and send.

Categories