How to send blog and page comment as email in Kaleo Workflow in Liferay 6.1? - workflow

I'm able to send notification about new comments, but I'd like to send the comment as part of the email. Here's what I got so far:
<notification>
<name>Notification</name>
<description>Notifies about new blog or page comments</description>
<template>
<![CDATA[
<p>
There's a new comment at page ${page_url} by ${user_name} :
<#if comment != "" >
<br /><strong>${comment}</strong>
</#if>
</p>
<p>With Love,<br /><strong>Liferay</strong></p>
]]>
</template>
<template-language>freemarker</template-language>
<notification-type>email</notification-type>
<recipients>
<role>
<role-type>regular</role-type>
<name>Portal Content Reviewer</name>
<auto-create>false</auto-create>
</role>
</recipients>
<execution-type>onEntry</execution-type>
</notification>
How would I assign the ${page_url}, ${user_name} and ${comment}?

Ok, $serviceContext has everything I needed. Note that I changed template language to velocity. For example:
<template>
<![CDATA[
## All attributes
##set ( $debug = ${serviceContext.getAttributes()} )
## URL to page:
#set ( $url = ${serviceContext.getAttribute("contentURL")} )
##Latest comment
#set ( $body = ${serviceContext.getAttribute("body")} )
<p>
There's a new comment at page $url :
<br /><strong>$body</strong>
</p>
]]>
</template>

Related

TYPO3 realURL and userfunction form

I post data and redirect to another page with a userfunction and a simple form like the following example:
<?php
class user_test
{
public function getForm() {
$form = '
<form action="#" method="post">
<input type="text" name="test" value="test" />
<input type="submit" name="send" value="send" />
</form>
';
$postArray = t3lib_div::_POST();
if ( isset( $postArray['send'] ) ) {
header( 'Location: index.php?id=2' );
}
return $form;
}
}
this works fine if realURL is deactivated, but if I activate realURL this form leads me always to the homepage after submit :(.
The typoscript part looks as follows:
prefixLocalAnchors = all
simulateStaticDocuments = 0
baseURL = http://test.de
tx_realurl_enable = 1
realURL works for speaking URLs and other forms like powermail forms, but my own forms leads to homepage, hope you can help me :).
UPDATE
If I remove the hash from action attribute: 'action="#"' of this form it is working, is this solution passable?
Removing the action attribute from the form was working.

How to configure WAMP and Smtp server

I have spent a significant time looking for an answer, and tried every solution without success :/
Basically I want to use wamp server to create contact form that will be sent to my mail address.
I have wamp running but for the life of me I can't figure out why I wouldn't receive the mails, I either get the 404 page when submitting the form, or lately "Warning: mail(): SMTP server response: 553 sorry, that domain isn't in my list of allowed rcpthosts".
I am now looking for a solution that will at least send the form to my address, whether it's secured or not I just want to see an actual mail successfully sent.
Thanks !
edit: here is the code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Contact Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="page-wrap">
<div id="contact-area">
<form method="post" action="contactengine.php">
<label for="Name">Name:</label>
<input type="text" name="Name" id="Name" />
<label for="Email">Email:</label>
<input type="text" name="Email" id="Email" />
<label for="Message">Message:</label><br />
<textarea name="Message" rows="20" cols="20" id="Message"> </textarea>
<input type="submit" name="submit" value="Submit" class="submit-button" />
</form>
<div style="clear: both;"></div>
</div>
</div>
</body>
</html>
--then the contact engine--
<?php
$EmailFrom = "myadress#mail.com";
$EmailTo = "myadress#mail.com";
$Subject = "Nice & Simple Contact Form by CSS-Tricks";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
--then the thanks message--
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN">
<head>
<title>A Nice & Simple Contact Form</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="page-wrap">
<img src="images/title.gif" alt="A Nice & Simple Contact Form" />
<p>By CSS-Tricks</p>
<br /><br />
<h1>Your message has been sent!</h1><br />
<p>Back to Contact Form</p>
</div>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-68528-29";
urchinTracker();
</script>
</body>
</html>
Windows does not come with a Mail Server so just calling mail() will work as far as php is concerned but the mail goes nowhere.
You either need to install a mail server or use something like the PHPMailer library to allow you to send SMTP mails via something like Yahoo or Google.

Using ReCaptcha with my custom form in Joomla

I'm trying to use JFormFieldCaptcha to work on my custom jForm. I managed to get the job done with registration and contact forms. However i want to build my own contact form which is based on an XML file somehow look like this:
<form>
<fieldset addfieldpath="<path to JFormFieldCaptcha class>">
<field
name="captcha" label="Captcha" description="COM_DEZTOUR_ORDER_CAPTCHA_DESC"
type="text" validate="captcha"
/>
</fieldset>
</form>
i cannot figure out why this code not working. Any help would be appriciated!
In order to use Joomla ReCaptcha plugin -
1)Get recaptcha keys from http://www.google.com/recaptcha
2)Set these keys to recaptcha plugin and activate it if it's not.
3) Go to Global Configuration=>Site=>Default Captcha
and set "Default Captcha"=>"Captcha - ReCaptcha"
4)Create xml form instance which has your captcha field
$form =& JForm::getInstance('myform','path/to/form/form.xml');
5)Create fields inside form-
$fieldSets = $form->getFieldsets();
foreach ($fieldSets as $name => $fieldSet) :
?>
<?php
foreach ($form->getFieldset($name) as $field):
?>
<p>
<?php if (!$field->hidden) : ?>
<span class="formlabel"><?php echo $field->label; ?></span>
<?php endif; ?>
<span class="control"><?php echo $field->input; ?></span>
</p>
<?php
endforeach;
?>
<div class="clr"></div>
<?php
endforeach;
6)After form submission validate form-
$post = JRequest::get('post');
jimport( 'joomla.form.form' );
$form =& JForm::getInstance('myform','path/to/form/form.xml');
$res = $form->validate($post);
XML form example-
<?xml version="1.0" encoding="utf-8"?>
<form
addfieldpath="/administrator/components/com_franchise/models/fields">
<fieldset name="information">
<field id="name"
name="name"
type="text"
label="Name"
description=""
class="inputbox"
size="30"
default=""
required="true"
/>
<field
name="captcha"
type="captcha"
label="COM_CONTACT_CAPTCHA_LABEL"
description="COM_CONTACT_CAPTCHA_DESC"
validate="captcha"
/>
</fieldset>
</form>
You can also try this-
How to use joomla recaptcha plugin to my custom Module

Magento Contact Form - been receiving email from myself

For some reason, when a customer submit the contact form, it appears in my gmail that the email was sent from myself, not from my customer.
Please check out the pictures so you know what I am talking about.
http://i.stack.imgur.com/QsACc.jpg
This image shows the email came from myself
http://i.stack.imgur.com/nghG2.jpg
Look at the arrow, this is what I see every email that comes from the contact from. Same name, same title.
This is really annoying because when many people use this, there is no way I can tell which one is which.
This is my contact page: meome.vn/lien-he
There might be some code to put in the email template that I don't know. Anyway if anyone knows how to fix this, please help me. I really appreciate it.
Did you check your email configuration in the backend.
Admin -> System -> configuration -> Store Email Addressess and
Admin -> System -> configuration -> Contacts -> Email options
Technically, this is a duplicate of Change 'From' field of magento contact form email to the sender but I put a complete and thorough answer here. A simple core hack is one answer provided there.
I am determined to not hack core files, so I solved this problem by making a custom controller. I read up and it seemed easy enough... and also no extensions on the market offer the goals I set out to accomplish: 1) have customer email & name on the From; 2) simple human input for anti spam; and 3) a couple custom fields, 3 of which are actually product attributes.
The files to accomplish this are:
$ find -type f
./Cycleworks/Cycleworks_ContactExtended.xml
./Cycleworks/ContactExtended/controllers/IndexController.php
./Cycleworks/ContactExtended/Helper/Data.php
./Cycleworks/ContactExtended/etc/config.xml
And now for the files themselves... The first XML file tells Magento about your custom override.
// copy this to app/etc/modules/
./Cycleworks/Cycleworks_ContactExtended.xml
<?xml version="1.0"?>
<config>
<modules>
<Cycleworks_ContactExtended>
<active>true</active>
<codePool>local</codePool>
</Cycleworks_ContactExtended>
</modules>
</config>
The remainder of the files go in app/code/local/. Below, I copied the postAction() function from the original controller and then added my code at the top and then made the one change in ->sendTransactional()
./Cycleworks/ContactExtended/controllers/IndexController.php
<?php
require_once 'Mage/Contacts/controllers/IndexController.php';
class Cycleworks_ContactExtended_IndexController extends Mage_Contacts_IndexController
{
public function postAction()
{
$post = $this->getRequest()->getPost();
if ( $post ) {
if( stripos( $post["people"],"tires") ===FALSE ){
Mage::getSingleton('customer/session')->addError("Please correctly answer the question to confirm you are human.<br>\"".$this->getRequest()->getPost("people")."\" is not correct.");
$this->_redirect('*/*/');
return;
}
$extras=Array( "bike_year","bike_make","bike_model","bike_model_ext" );
foreach($extras as $field) {
if( $post[$field] == "empty" )
$post[$field]= "----";
}
$comment = $post['comment']."\nMage::getStoreConfig(self::XML_PATH_EMAIL_SENDER)=\n'".Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER)."'";
$post['comment']= nl2br($comment);
$translate = Mage::getSingleton('core/translate');
/* #var $translate Mage_Core_Model_Translate */
$translate->setTranslateInline(false);
try {
...
...
...
$mailTemplate->setDesignConfig(array('area' => 'frontend'))
->setReplyTo($post['email'])
->sendTransactional(
Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
array( 'name'=>$post['name'],'email'=> $post['email'] ), // Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER), //
Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
null,
array('data' => $postObject)
);
...
...
...
}
}
Nice and empty shell. And yes, these all have opening <?php tags but not closing ones??
./Cycleworks/ContactExtended/Helper/Data.php
<?php
class Cycleworks_ContactExtended_Helper_Data extends Mage_Core_Helper_Abstract
{
}
And the XML in the custom module:
./Cycleworks/ContactExtended/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Cycleworks_ContactExtended>
<version>0.0.01</version>
</Cycleworks_ContactExtended>
</modules>
<frontend>
<routers>
<contacts>
<args>
<modules>
<Cycleworks_ContactExtended before="Mage_Contacts">Cycleworks_ContactExtended</Cycleworks_ContactExtended>
</modules>
</args>
</contacts>
</routers>
</frontend>
<global>
<helpers>
<contactextended>
<class>Cycleworks_ContactExtended_Helper</class>
</contactextended>
</helpers>
</global>
</config>
That's all the backend. As for the form itself, I added this code to form.phtml below the comments block and above the closing </ul> tag. For most people this file is in app/code/design/frontend/default/default/template/contacts. Since I have a TM template that I purchased, mine is in default/a034/template/contacts
<?php
$confirm_people_question="Motorcycles have two of these and rhymes with plires"; // CKCK form anti-spam
?>
<li>
<label for="people" class="required"><em>*</em><?php echo $confirm_people_question ?></label>
<div class="input-box">
<input name="people" id="people" title="Please confirm you are people" value="" class="required-entry input-text" type="text" />
</div>
</li>
<?php
// from http://www.sharpdotinc.com/mdost/2009/04/06/magento-getting-product-attributes-values-and-labels/
$wanted=Array("make","model","engine_size"); // note that each attribute needs to be searchable
$attributes = Mage::getModel('catalogsearch/advanced')->getAttributes(); // $productAttrs = Mage::getResourceModel('catalog/product_attribute_collection');
$attributeArray=array();
foreach($attributes as $a){
if( in_array( $a->getAttributeCode(), $wanted) ){
foreach($a->getSource()->getAllOptions(false) as $option){
$attributeArray[$a->getAttributeCode()][$option['value']] = $option['label'];
}
}
}
?>
<li>
<div class="ymm">
<label for="bike_year">Year</label><br>
<select id="year" name="bike_year">
<option value="empty"></option>
<? for( $idx=date("Y"); $idx >= 1985; $idx-- )
echo " <option value=\"$idx\">$idx</option>\n";
?>
</select>
</div>
<div class="ymm">
<label for="bike_make">Make</label><br>
<select id="make" name="bike_make">
<option value="empty"></option>
<? foreach( $attributeArray['make'] as $id => $brand )
echo " <option value=\"$brand\">$brand</option>\n";
?>
</select>
</div>
<div class="ymm">
<label for="bike_model">Model</label><br>
<select id="model" name="bike_model">
<option value="empty"></option>
<? foreach( $attributeArray['model'] as $id => $model )
echo " <option value=\"$model\">$model</option>\n";
?>
</select>
</div>
<div class="ymm">
<label for="bike_model_ext">More</label>
<div class="input-box">
<input type="text" size="15" value="" id="model_ext" name="bike_model_ext" class="input-text">
</div>
</div>
</li>
I almost forgot, the final key to the puzzle is the mail template in the admin area: System - Transactional Emails. Find your HTML contact template (or make a new one and do not convert it to plain text) and this is what I've got:
<body style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<div style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<table>
<tr><td>Name</td><td>{{var data.name}}</td></tr>
<tr><td>E-mail</td><td>{{var data.email}}</td></tr>
<tr><td>Telephone</td><td>{{var data.telephone}}</td></tr>
</table>
<P>
<fieldset><legend>Subject: {{var data.subject}}</legend>
{{var data.comment}}
</fieldset>
Bike info: {{var data.bike_year}} {{var data.bike_make}} {{var data.bike_model}} {{var data.bike_model_ext}}
</div>
</body>
I never really thought I would have made my own custom module, but I followed the recipes I found on here and elsewhere and put this together. It also behaves correctly when the capcha fails. I did try to research how to give the option to CC the customer with their own contact, but I couldn't find anything.
Later, I tried to make a custom module to allow an alternate admin notification email template for new orders but the knowledge I had learned from above wasn't enough. :P So my knowledge and comfort with Magento is perhaps above "dangerous hack", but I still have a long way to go.

Contact form with file attachment?

I have a contact form which is a template for pages on wordpress that I use if I need a contact form. All works fine but I want to add the capability of adding a file attachment so when the user fills in their name etc they can upload a photo and that photo will be sent to be me as an attachment.
I have a perfect working contact form and I only want to add that functionality to it. All my current code does all this it sends the name of the person their email address and their message to my email, all I'm missing is the attachment feature. I've been looking at alot of contact forms with this feature but to integrate that feature to my sendmail.php seems very hard as the coding style is completely different. Here is a demo of this in action. demo
This is my php file that has the form in it.
<?php get_header(); ?>
<script type="text/javascript">
$(document).ready(function(){
$('#contact').ajaxForm(function(data) {
if (data==1){
$('#success').fadeIn("slow");
$('#bademail').fadeOut("slow");
$('#badserver').fadeOut("slow");
$('#contact').resetForm();
}
else if (data==2){
$('#badserver').fadeIn("slow");
}
else if (data==3)
{
$('#bademail').fadeIn("slow");
}
});
});
</script>
<!-- begin colLeft -->
<div id="colLeft">
<!-- Begin .postBox -->
<div class="postBox">
<div class="postBoxTop"></div>
<div class="postBoxMid">
<div class="postBoxMidInner first clearfix">
<h1>Contact Us</h1>
<p><?php echo get_option('alltuts_contact_text')?></p>
<p id="success" class="successmsg" style="display:none;">Your email has been sent! Thank you!</p>
<p id="bademail" class="errormsg" style="display:none;">Please enter your name, a message and a valid email address.</p>
<p id="badserver" class="errormsg" style="display:none;">Your email failed. Try again later.</p>
<form id="contact" action="<?php bloginfo('template_url'); ?>/sendmail.php" method="post">
<label for="name">Your name: *</label>
<input type="text" id="nameinput" name="name" value=""/>
<label for="email">Your email: *</label>
<input type="text" id="emailinput" name="email" value=""/>
<label for="comment">Your message: *</label>
<textarea cols="20" rows="7" id="commentinput" name="comment"></textarea><br />
<input type="submit" id="submitinput" name="submit" class="submit" value="SEND MESSAGE"/>
<input type="hidden" id="receiver" name="receiver" value="<?php echo strhex(get_option('alltuts_contact_email'))?>"/>
</form>
</div>
</div>
<div class="postBoxBottom"></div>
</div>
<!-- End .postBox -->
</div>
<!-- end colleft -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
and here is the file that handles the sending of the mail.
<?php
if(isset($_POST['submit'])) {
error_reporting(E_NOTICE);
function valid_email($str)
{
return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*#([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
}
if($_POST['name']!='' && $_POST['email']!='' && valid_email($_POST['email'])==TRUE && strlen($_POST['comment'])>1)
{
$to = preg_replace("([\r\n])", "", hexstr($_POST['receiver']));
$from = preg_replace("([\r\n])", "", $_POST['email']);
$subject = "Website contact message from ".$_POST['name'];
$message = $_POST['comment'];
$match = "/(bcc:|cc:|content\-type:)/i";
if (preg_match($match, $to) ||
preg_match($match, $from) ||
preg_match($match, $message)) {
die("Header injection detected.");
}
$headers = "From: ".$from."\r\n";
$headers .= "Reply-to: ".$from."\r\n";
if(mail($to, $subject, $message, $headers))
{
echo 1; //SUCCESS
}
else {
echo 2; //FAILURE - server failure
}
}
else {
echo 3; //FAILURE - not valid email
}
}else{
die("Direct access not allowed!");
}
function hexstr($hexstr) {
$hexstr = str_replace(' ', '', $hexstr);
$hexstr = str_replace('\x', '', $hexstr);
$retstr = pack('H*', $hexstr);
return $retstr;
}
?>
Thanks!
You can read this simple tutorial to know what needs to be done to add file upload support to your current form:
http://www.tizag.com/phpT/fileupload.php
Hope it helps!
EDITED
After the upload process, you can do like this:
if (file_exists($_FILES['uploaded']['tmp_name'])) {
$mail->AddAttachment($_FILES['uploaded']['tmp_name'], $_FILES['uploaded']['name']);
}
What this does is to add an attachment to your email by calling the AddAttachment from PHPMailer, and using the file just uploaded from the TMP folder of your server... so no actual storage of the file is necessary.
You can use
http://wordpress.org/plugins/contact-form-7/
It has a option for Upload field as well as all validations, really easy to use.
You just need to enter shortcode and you can use the contact form anywhere you want.