wpcf7 dynamic email-tag content - contact-form-7

Description:
WordPress Contact Form 7;
Mailing using smtp;
Form Settings: "use html-format" + "mail2 use html-format" checked;
Form Settings: Email body : just one mail-tag [calculated-template];
Problem with paragraph tag solved (all mail-tags upon receiving are shown inside "p" html-tag);
[calculated-template] is a mail-tag dynamically filled with html, based on submitted objects handled by VueJS2 on frontend;
[calculated-template] is populated by hooking at action 'wpcf7_posted_data':
add_action('wpcf7_posted_data', array('vue_handler','handle'), 1, 1);
vue_handler::handle($data) receives $data array with some wpcf7 data which can be modified. Contents of $data array:
_wpcf7 = "1166"
_wpcf7_version = "4.9.2"
_wpcf7_locale = "ru_RU"
_wpcf7_unit_tag = "wpcf7-f1166-p1167-o1"
_wpcf7_container_post = "1167"
columns-stringified = ""
fences-stringified = ""
your-name = "name"
your-email = "email#test.com"
calculated-template = ""
Then vue_handler::handle($data) injects html into email-tag [calculated-template].
Problem:
Finally [calculated-template] html-contents rendered escaped (Mailtrap.io, "HTML Source" tab):
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Title</title>
</head>
<body>
<h1>Example Header</h1>
</body>
</html>
The main idea of the snippet: opening and closing html-tag symbols "<", ">" rendered escaped: "<", ">";

SOLVED
By using another hook wpcf7_before_send_mail
In which I fully replaced mail body with my dynamic html.
List of all hooks:
http://hookr.io/plugins/contact-form-7/4.5.1/hooks/#index=a

Related

How to populate HTML data to Grafana Ajax Plugin

I have a html content that gets generated dynamically and i want to display the same in the Grafana. Manually populating the Ajax Plugin is not feasible. I understand that the Ajax plugin can be used for the same. How can i send the html content to this plugin and what are the different parameters (image below) that have to be updated to get the data right?
I’m using Python to push the data to the Influxdb. example below -
The variable htmloutput contains the html data that has to be displayed.
client = InfluxDBClient(host='10.10.10.10', port=8086)
client.switch_database('TesDB')
json_body = [
{
"measurement": "MS1",
"tags": {
"Server": QA1,
},
"time": timestamp,
"fields": {
"HTMLCONTENT": htmloutput
}
}
]
client.write_points(json_body)
Sample HTML Output that I get which needs to be displayed -
HTML Code -
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-type" content="text/html;charset=UTF-8"><title>Errors</title><link rel="stylesheet" type="text/css" href="styles.css"><script src="code.js" type="text/javascript"></script></head><body onload="preparepage();"><input type="hidden" id="imageBase" value="img/"><a name="17">Problem 1</a></h3><div id="exp17"><div class="important"><div><p>104 errors of <b>General Exceptions</b>, at <b>Overview page</b> occupy <b>26.92%</b> in total. <br><br><b>Keywords</b><br>General<br>Unavailable, Temporary<br></div></div></div></div><br>
</body></html>
Thanks in advance.

How can I generate pages in Assemble based on an different json files?

So I have a folder rules that that looks like this:
rule-001.json
rule-002.json
rule-003.json
Each *.json file is of a unified format:
{ name: 'AAA', descriptions: 'BBB' }
How can I generate a pages based on these files in Assemble?
The short answer is that you need to load your JSON data in your Gruntfile and use it to replace the Assemble pages object.
I have written a blog post about generating pages from data, based on the Assemble Blog Theme sample. In both cases, the pages data was stored in a single JSON file.
In your case, you need to load the data from all of JSON files in your Gruntfile, and transform the data into the pages format. You can do this any number of ways, but one simple way would be to write a function in your Gruntfile that does this:
function loadDataPages (jsonFileSpec) {
var path = require("path");
var jsonPaths = grunt.file.expand(jsonFileSpec);
var jsonPages = jsonPaths.map(function (jsonPath) {
var jsonData = grunt.file.readJSON(jsonPath);
var outputFileName = path.basename(jsonPath, path.extname(jsonPath)) + ".html";
var jsonPage = {
"data": jsonData,
"content": "This is the body content for page " + outputFileName,
"filename": outputFileName
};
return jsonPage;
});
return jsonPages;
}
and then you need to load this data object in your Grunt config and pass it to Assemble's pages option:
grunt.initConfig({
assemble: {
data: {
options: {
flatten: true,
layout: "source/templates/layouts/custom-data-layout.hbs",
pages: loadDataPages("source/custom-data/*.json")
},
files: {
"output/custom-data-pages/": ["source/custom-data/index.hbs"]
}
}
}
// ...
});
Here is what the layouts might look like:
custom-data-layout.hbs
<!DOCTYPE html>
<html>
<head>
<title>Custom Data - {{name}}</title>
</head>
<body>
<h1>Custom Data - {{name}}</h1>
<p>{{ description }}</p>
{{> body }}
</body>
</html>
index.hbs
---
layout: false
title: Custom Data Index
---
<!DOCTYPE html>
<html>
<head>
<title>{{title}}</title>
</head>
<body>
<h1>{{title}}</h1>
<ul>
{{#each pages }}
<li>{{basename}}</li>
{{/each}}
</ul>
</body>
</html>
Something like this should work for you. You just create separate Assemble tasks and call the main Assemble task with grunt.
https://gist.github.com/davidwickman/a0bf961e3099ea6b9c35

Adding inline images to Mailgun emails using Scala and Play WS

I can succesfully make POST requests to Mailgun and receive the emails as expected. I'm trying to inline an image into an email and can't work out how to do it.
Looking at https://documentation.mailgun.com/user_manual.html#sending-via-api and selecting Java, I can see that the example given constructs a FileDataBodyPart with "inline", the File reference and the MediaType. Looking at the curl example, this seems rather unnecessary as that just references a file.
Here is my method for sending an email:
def send(message:EmailMessage) = {
val postMessage = Map("from" -> Seq(message.from), "to" -> Seq(message.to), "subject" -> Seq(message.subject), "text" -> Seq(message.text), "html" -> Seq(message.html.toString()))
val logo = FileBody(Play.getExistingFile("/public/images/logo.png").get)
WS.url(apiUrl).withAuth("api", myKey, WSAuthScheme.BASIC).withBody(logo).post(postMessage)
}
The message.html.toString looks like the following:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body style="background-color:#9B59B6; padding:10px">
<img src="cid:logo.png">
<h1 style="color:#FFF">Activate!</h1>
</body>
</html>
The logo.png file is found when sending the email and the email comes through fine, but with no image. This is what the email source looks like once it arrives at gmail:
Mime-Version: 1.0
Content-Type: text/html; charset="ascii"
Content-Transfer-Encoding: 7bit
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body style="background-color:#9B59B6; padding:10px">
<img src="cid:logo.png">
<h1 style="color:#FFF">Activate!</h1>
</body>
</html>
I can't see any base64 encoding of the image in the email. As the curl example appeared to just be passing a file as part of the POST, I though I'd try that. Here is what I did:
def send(message:EmailMessage) = {
val logoFile = Play.getExistingFile("/public/images/logo.png").get
val source = Files.readAllBytes(Paths.get(logoFile.getAbsolutePath))
val logoBase64 = Base64.encodeBase64String(source)
val postMessage = Map("from" -> Seq(message.from), "to" -> Seq(message.to), "subject" -> Seq(message.subject), "text" -> Seq(message.text), "html" -> Seq(message.html.toString()), "inline" -> Seq(logoBase64))
WS.url("https://api.mailgun.net/v2/sandboxaa9afcea1f2e4d5db5e2c080f7784b74.mailgun.org/messages").withAuth("api", "key-f165695d4c72e929ff8215115e648c95", WSAuthScheme.BASIC).post(postMessage)
}
I converted the logo into base64 and POSTed that like the other parameters. Still no joy.
What am I missing here? Do I need to pass this in the body, but somehow specify that this is an "inline" file?
I solved this by using Jersey, as suggested in the section on libraries: https://documentation.mailgun.com/libraries.html#java
I imported Jersey in sbt using the following:
libraryDependencies += "com.sun.jersey" % "jersey-core" % "1.18.3"
libraryDependencies += "com.sun.jersey" % "jersey-client" % "1.18.3"
libraryDependencies += "com.sun.jersey.contribs" % "jersey-multipart" % "1.18.3"
and then created my Email sending object like so:
object Email {
val client = Client.create()
client.addFilter(new HTTPBasicAuthFilter("api", current.configuration.getString("mailgun.api.key").get))
val webResource = client.resource(current.configuration.getString("mailgun.api.url").get)
def send(message:EmailMessage) = {
val form = new FormDataMultiPart
form.field("from", message.from)
form.field("to", message.to)
form.field("subject", message.subject)
form.field("text", message.text)
form.field("html", message.html.toString())
val logo = Play.getExistingFile("/public/images/logo.png").get
form.bodyPart(new FileDataBodyPart("inline", logo, MediaType.APPLICATION_OCTET_STREAM_TYPE))
webResource.`type`(MediaType.MULTIPART_FORM_DATA_TYPE).post(form)
}
}
I hope this helps someone.

phonegap submit form, how to send to my email

I am building simple phonegap android app.
i make simple html form with few input fields (Name, Last name, Question).
I want that when user fill input fields (Name, Last name, Question) and click Submit to send to my email address. Just that.
Do you have any idea how to do that with phonegap?
Thank you
You could do it easily by using php or .net (as your selection) with AJAX Call
Just Create One HTML page which display form to User for filling up data and send it.
Here I saw you how I done with PHP (Use phpmailer. for more, visit : http://phpmailer.worxware.com/index.php?pg=examplebmail)
HTML Form
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<form action="#!" method="post">
<input type = "text" name="cname" />
<input type = "number" name="cnumber" />
<input type = "email" name="cemail" />
<input type = "submit" value="Submit" onclick="UpdateRecord()" />
</form>
<script>
function UpdateRecord()
{
// Social Links
GolbalURL = "http://www.yourserverpathtophpfile.com";
var cname = $("[name='cname']").val();
var cnumber = $("[name='cnumber']").val();
var cemail = $("[name='cemail']").val();
jQuery.ajax({
type: "POST",
url: GolbalURL+"sendemail.php",
data: "cname="+ cname+"& cnumber="+ cnumber+"& cemail="+ cemail,
dataType: "html",
cache: false,
success: function(response)
{
alert("Email Sent");
}
});
}
</script>
</body>
</html>
Sendmail.php
<?php
$cname = $_REQUEST['cname'];
$cnumber = $_REQUEST['cnumber'];
$cemail = $_REQUEST['cemail'];
require_once('class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = "Name : ".$cname."Number : ".$cnumber."Email : ".$cemail;
$mail->SetFrom($cemail, $cname);
$address = "youremail#id.com";
$mail->AddAddress($address, "Your Name");
$mail->Subject = "Your Subject";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
Do not forgot to upload your dynamic files to server and give it permissions. Or You can also call device's default mail application from code, check PHONEGAP EMAIL COMPOSER
GIT Link Of Email Compo.
https://github.com/katzer/cordova-plugin-email-composer/blob/172605ee12e58d5e5809e4e031b3b96cead143ac/README.md
You can do using Cordova EmailComposer Plugin for Android . Add this function on your submit button click. For installation follow these steps .
https://github.com/katzer/cordova-plugin-email-composer
function emailComposer(){
window.plugin.email.isServiceAvailable(
function (isAvailable) {
if(isAvailable){
window.plugin.email.open({
to: [''],
cc: [''],
bcc: [''],
subject: '',
body: ''
});
}else{
alert('Service is not available');
}
}
);
}
**JQUERY - CALL PHP SCRIPT TO POST DATA**
var ajax_call = serviceURL;
var form_data = $('#form').serialize();
$.ajax({
type: "POST",
url: ajax_call,
data: form_data,
dataType: "json",
success: function(response) {
//called when successful
},
error: function(e) {
//called when there is an error
//console.log(e.message);
}
});
Examples
There are plugins to compose emails, but it won't send it automatically. You really need to use a back end service to handle this for you. You can setup your own using any app language (PHP, ColdFusion, etc), or consider a service like WuFoo perhaps.

Sharing url to Facebook from AS3 website

I'm trying to share a URL from a flash as3 website, and i can't make it work quite properly...
I tried both ways given here : How to create a share button in AS3
First one works :
import flash.net.navigateToURL;
import flash.net.URLVariables;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
share_btn.addEventListener(MouseEvent.CLICK, shareClickHandler);
function shareClickHandler(evt:MouseEvent):void
{
var varsShare:URLVariables = new URLVariables();
varsShare.u = 'http://domain.com/pageN.html';
varsShare.t = 'Title Page';
var urlFacebookShare:URLRequest = new URLRequest('http://www.facebook.com/sharer.php');
urlFacebookShare.data = varsShare;
urlFacebookShare.method = URLRequestMethod.GET;
navigateToURL(urlFacebookShare, '_blank');
}
But, the post says :
In order to use a picture add the following Metatags:
<meta name="title" content="my title" />
<meta name="description" content="my description" />
<link rel="image_src" href="images/thumbnail_image.jpg" />
But HOW ????
The second solution shows how to add parameters:
var req:URLRequest = new URLRequest();
req.url = "http://www.facebook.com/dialog/feed";
var vars:URLVariables = new URLVariables();
vars.app_id = "000000000000"; // your application's id
vars.link = "http://YourSite.com";
vars.picture = "https://www.google.com/intl/en_com/images/srpr/logo3w.png";
vars.name = "name name";
vars.caption = "caption caption caption";
vars.description = "description description description";
vars.message = "message message message message message";
vars.redirect_uri = "http://YourSite.com";
req.data = vars;
req.method = URLRequestMethod.GET;
navigateToURL(req, "_blank");
But it's NOT using the Facebook sharer.....
I tried many many different ways to combine both solutions but i get nothing but weird url not working...
Please, can someone help me with that, or show me how to use that second solution but with the sharer ?
Thanks a lot for any help
You need to add OpenGraph Meta Tags to the Page you are trying to share (http://domain.com/pageN.html in your example above`). The metatags you've given in your question should be added there so the Facebook Sharing Script can pick it up.
Add the below code between the <head> and </head> tags in your HTML code:
<meta name="title" content="my title" />
<meta name="description" content="my description" />
<link rel="image_src" href="images/thumbnail_image.jpg" />
what I usually do - I create a facebook application - Website with Facebook Login, add Apps domains, then in your html add this javascript function:
function postToFacebook(link){
var caption = encodeURIComponent("this is cool");
var name = encodeURIComponent("My cool Site");
var pathToPicture = "http://yoursite.com/coolpicture.jpg";
var redirect = "http://yoursite.com/redirect.html";
var id = "123456789098876"; // your application id
var theLink = link; // the link you want to share - this is passed as a variable from flash, similary you can pass any variables from flash
var fbencoded = "http://www.facebook.com/dialog/feed?app_id=" + id + "&link=" + theLink + "&picture=" + pathToPicture + "&name=" + name + "&caption=" + caption+ "&redirect_uri=" + redirect;
window.open(fbencoded, "_blank");
}
In flash whenever you want to share just call this javascript function and new window will be opened with facebook share window:
ExternalInterface.call("postToFacebook", "http://mysite.com/#/cool-page")
This way you can pass any vars to that function. For example you can have different pictures whenever someone is sharing, which would be impossible with just meta tags.....
Only thing is you have to create that redirect.html - which must be within your domain, that is linked to your application. In redirect you can have something simple as this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<meta http-equiv="REFRESH" content="0;url=http://www.facebook.com">
</head>
<body>
</body>
</html>
It would just redirect the user to facebook.
Hope this helps.
This is the way I got to use the Share Dialog from a button in AS3. I hope it helps you
import flash.net.navigateToURL;
share_btn.addEventListener(MouseEvent.CLICK, shareClickHandler);
function shareClickHandler(evt:MouseEvent):void
{
var fb_title = "titulo";
var fb_desc = "descripcion";
var fb_url = "http://mibff.com.mx/";
var fab_img = "http://mibff.com.mx/MiBFF_new.jpg";
var facebookSharer:String = "http://www.facebook.com/sharer.php?s=100&p[title]=" + fb_title + "&p[summary]=" + fb_desc + "&p[url]=" + fb_url + "&p[images][0]=" + fab_img;
var jscommand:String = "window.open('" + facebookSharer + "','win','width=626,height=316,toolbar=no,scrollbars=no,resizable=no');";
var sharer:URLRequest = new URLRequest("javascript:" + jscommand + " void(0);");
navigateToURL(sharer,"_self");
//trace(facebookSharer);
}