Magento Contact Form - been receiving email from myself - forms

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.

Related

CodeIgniter form_validation and form_error - delete original error message

I'm using CodeIgniter form_validation and
Everything works good except the original notification still appears in the top right.
Can anybody advise me how to delete the original notification?
I've inserted the PHP code into to view page.
<?php echo form_error('uname'); ?>
The form_error message appears the way I want but the original error message still appears in the top right, and I don't know how to delete that.
EDIT 01/08/19
Below is edited coding I've taken from the CI UserGuide.
Controller
<?php
class Form extends CI_Controller
{
public function index()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required', array('required' => 'You must provide a %s.'));
if ($this->form_validation->run() == FALSE)
{
$this->load->view('myform');
}
else
{
$this->load->view('formsuccess');
}
}
}
View
<html>
<head>
<title>My Form</title>
</head>
<body>
<?php echo validation_errors(); ?>
<?php echo form_open('form'); ?>
<h5>Username</h5>
<input type="text" name="username" value="" size="50" />
<h5>Password</h5>
<input type="text" name="password" value="" size="50" />
<div><input type="submit" value="Submit" /></div></form>
</body>
</html>
If the above is loaded the result will be the Username Text Box in the top left corner, and the Password Text Box below it.
If the Submit button is clicked without any content in the text boxes the following notifications appear in the top left corner and above the Text Boxes.
You must provide a Username.
You must provide a Password.
However, if I change the view page to the following, the same notifications STILL APPEAR IN THE TOP LEFT CORNER, as well as next to the Text Boxes, so in effect each notification appears twice.
<html>
<head>
<title>My Form</title>
</head>
<body>
<?php echo validation_errors(); ?>
<?php echo form_open('form'); ?>
<h5>Username</h5>
<input type="text" name="username" value="" size="50" />
<?php echo form_error('username'); ?>
<h5>Password</h5>
<input type="text" name="password" value="" size="50" />
<?php echo form_error('password'); ?>
<div><input type="submit" value="Submit" /></div></form>
</body>
</html>
It is the notifications that still appear in the top left corner, that I want to delete.
I can't find any coding that positions the notifications so I guess that comes from somewhere within the CI system.
I can position the form_error notifications by using css coding.
I found the problem.
<?php echo form_error('username'); ?> // When this is inserted.
<?php echo validation_errors(); ?> //This must be deleted.
Or put another way the coding above provides the notifications at the top right.

Magento Checkout Comment

i'm still a beginner at Magento and try to learn how to create Modules. Right now i'm working on a module, which allows the customer to add a comment during the checkout.
Now i got a problem to implement the textarea, i created a new file called "practice" under app/design/frontend/base/default/layout and under app/design/frontend/base/default/template. I upload the new layout-file in the config.xml file of my module. But there isnt any textarea during the checkout, even though the right template is uploaded (i activated the template path hint option to see the path of each Block).
app/code/local/Practice/CheckoutComments/etc/config.xml
<frontend>
<layout>
<updates>
<checkoutcomments>
<file>practice/checkoutcomments.xml</file>
</checkoutcomments>
</updates>
</layout>
</frontend>
Here is the code of the layout.xml file and the phtml.file i override:
app/design/frontend/base/default/layout/practice/checkoutcomments.xml
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<checkout_onepage_review translate="label">
<reference name="checkout.onepage.agreements">
<action method="setTemplate">
<template>practice/checkoutcomments/onepage/comment-agreements.phtml
</template>
</action>
</reference>
</checkout_onepage_review>
</layout>
app/design/frontend/base/default/template/practice/checkoutcomments/onepage/comment-agreements.phtml
<?php
/**
*
* #see Mage_Checkout_Block_Agreements
*/
?>
<!-- Start of CheckoutComments module code -->
<form action="" id="checkout-agreements" onsubmit="return false;">
<ol class="checkout-agreements">
<div>
<br /> <label for="checkoutcomments"><?php echo Mage::helper('core')->__('Add your Comment for this Order') ?></label>
<textarea name="checkoutcomments" id="checkoutcomments"
style="width: 450px; height: 100px;"></textarea>
</div>
<!-- End of CheckoutComment module -->
<?php if ($this->getAgreements()) : ?>
<?php foreach ($this->getAgreements() as $_a): ?>
<li>
<div class="agreement-content"
<?php echo ($_a->getContentHeight() ? ' style="height:' . $_a->getContentHeight() . '"' : '')?>>
<?php if ($_a->getIsHtml()):?>
<?php echo $_a->getContent()?>
<?php else:?>
<?php echo nl2br($this->escapeHtml($_a->getContent()))?>
<?php endif; ?>
</div>
<p class="agree">
<input type="checkbox" id="agreement-<?php echo $_a->getId()?>"
name="agreement[<?php echo $_a->getId()?>]" value="1"
title="<?php echo $this->escapeHtml($_a->getCheckboxText()) ?>"
class="checkbox" /><label for="agreement-<?php echo $_a->getId()?>"><?php echo $_a->getIsHtml() ? $_a->getCheckboxText() : $this->escapeHtml($_a->getCheckboxText()) ?></label>
</p>
</li>
<?php endforeach ?>
<?php endif; ?>
</ol>
</form>
I deactivated my module and overrode the code of app/design/frontend/base/default/template/checkout/onepage/agreements.phtml with my customized pthml.file from above, then the textarea appears! I guess that something is wrong with my configurationsfiles, but i reference to the right block, since the block is uploaded but there isnt any textarea.
I hope you can help me
Regards
I solved the question by accident:
In
app/design/frontend/base/default/layout/practice/checkoutcomments.xml
i changed the line
<template>practice/checkoutcomments/onepage/comment-agreements.phtml
</template>
to:
<template>practice/checkoutcomments/onepage/comment-agreements.phtml</template>
it seems that i choose a wrong autoformat in eclipse, but i'm wondering, that this makes such a huge difference
Regards

Make reCAPTCHA work on same Page(index.php)

Hello Every one i have a form and i want to add reCAPTCHA to it.
This is my form
<form action="index.php" method="POST">
<div class="header"></div>
<div class="headerimg">
<img border="0" src="logo.png" alt="AUD Confession" width="auto" height="auto">
<div class="headertxt">Confession</div>
</div>
<table font-family="inherit">
<tr><td class="comm" colspan="2">Comment: </td></tr>
<tr><td colspan="5"><textarea name="comment" rows="5" cols="50" id="comments" class="common" autofocus></textarea></td></tr>
<tr><td><?php
require_once('recaptchalib.php');
$publickey = "6Lc1RewSAAAAAO2Emd1_ICM5qUssQdfqF0vRiCE9"; // you got this from the signup page
echo recaptcha_get_html($publickey);
?></tr></td>
<tr><td colspan="2"><input type="submit" name="submit" class="myButton" value="SUBMIT"></td></tr>
</table>
</form>
The Problem is that reCAPTCHA check it on action="verify.php" and show whether it is correct or not but do not submit the form values on index.php.
Codes on verify.php
<?php
require_once('recaptchalib.php');
$privatekey = "6Lc1RewSAAAAAPBsu1AnNhJpIbS64XR0fLqEioVb";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
} else {
// Your code here to handle a successful verification
}
?>
I want reCAPTCHA to check on the same page i:e; action="index.php".
Please Help.
Or suggest something similar.
I myself figured it out and got the solution.
All I have to do is add some codes in the place of
// Your code here to handle a successful verification
The php codes that insert User Data into database.

Is there any way possible to apply form requirements to a drop down field in a PHP contact form?

I would like to create a requirement that if nothing is selected from a drop down field in my contact form that a message will come up saying "Please choose", and the form will not be able to be submitted unless something is chosen. I have gotten requirements to work on all of my text input forms, but cannot figure out how to create one for the drop down field.
The drop down HTML looks like this:
<div class='container'>
<label for='destemail' > Which department are you trying to reach?*</br> You must select a department.</label></br>
<select name="destemail" id="destemail">
<?php foreach ($emailAddresses as $name => $email) { ?>
<option value="<?php echo htmlspecialchars($name); ?>"><?php echo htmlspecialchars($name) ; ?></option>
<?php } ?></select>
<span id='contactus_destemail_errorloc' class='error'></span>
</div>
I got the other form requirements to work like so:
The HTML -
<div class='container'>
<label for='name' >Your Full Name*: </label><br/>
<input type='text' name='name' id='name' value='<?php echo $formproc->SafeDisplay('name') ?>' maxlength="50" /><br/>
<span id='contactus_name_errorloc' class='error'></span>
</div>
The Javascript -
<script type='text/javascript'>
<![CDATA[
var frmvalidator = new Validator("contactus");
frmvalidator.EnableOnPageErrorDisplay();
frmvalidator.EnableMsgsTogether();
frmvalidator.addValidation("name","req","Please provide your name");
</script>
The PHP -
//name validations
if(empty($_POST['name']))
{
$this->add_error("Please provide your name");
$ret = false;
}
I tried the exact same coding for the drop down but with the different id names where appropriate, and it didn't work. Why doesn't this same method work for the drop down?
Help much appreciated!
I can't see what the Validator() code is doing, but you can just check to see whether the select field is empty using Javascript or jQuery.
jQuery way:
if( !$('#destemail').val() ) {
alert('Empty');
}
The problem may lie in that your select box actually does have a value, which is whatever the first value printed out in it is. The Validation function may be checking for any value, and since the select does have one, it returns as valid.
You could set up a default value to show first, something like "Please select a Department", and then do the jquery/javascript check for that text. If it exists, then you know an option has not been selected.

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.