Magento联络表格 - 自己收到邮件 [英] Magento Contact Form - been receiving email from myself

查看:155
本文介绍了Magento联络表格 - 自己收到邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,当客户提交联系表单时,我的邮件中会显示电子邮件是从我自己发送的,而不是我的客户。
请检查图片,以便知道我在说什么。



http://i.stack.imgur.com/QsACc.jpg
此图显示了自己的电子邮件



http://i.stack.imgur。 com / nghG2.jpg
看看箭头,这是我看到来自联系人的每封电子邮件。相同的名称,相同的标题。



这真的很烦人,因为很多人使用这个,没有办法可以告诉哪一个是哪个。



这是我的联系页面:meome.vn/lien-he
可能有一些代码放在我不知道的电子邮件模板中。无论如何,如果有人知道如何解决这个问题,请帮助我。对此,我真的非常感激。

解决方案

从技术上讲,这与将magento联系表格邮件的'From'字段更改为发件人,但我在此处提供了一个完整而彻底的答案。一个简单的核心攻击是在那里提供的一个答案。



我决心不要攻击核心文件,所以我通过制作一个自定义控制器来解决这个问题。我阅读了,看起来很简单,市场上也没有任何扩展功能可以实现我的目标:1)有客户电子邮件和来自的名字2)反垃圾邮件的简单人为输入; 3)几个自定义字段,其中3个实际上是产品属性。<​​/ p>

要完成的文件是:

  $ find -type f 
./Cycleworks/Cycleworks_ContactExtended.xml
./Cycleworks/ContactExtended/controllers/IndexController.php
./Cycleworks /ContactExtended/Helper/Data.php
./Cycleworks/ContactExtended/etc/config.xml



< hr>

现在对于文件本身...第一个XML文件告诉Magento你的自定义覆盖。

  //将其复制到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>






其余的文件进入应用程序/代码/本地/ 。下面,我从原始控制器复制了 postAction()函数,然后在顶部添加了我的代码,然后在 - > 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 / ) - > addError(请正确地回答问题以确认你是人类。< br> \$ this-> getRequest() - > getPost(people)\不正确。);
$ 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']。\\\
Mage :: getStoreConfig(self :: XML_PATH_EMAIL_SENDER)= \\\
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);
尝试{
...
...
...
$ 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,
数组('data'=> $ postObject)
);
...
...
...
}
}






尼斯和空壳。是的,这些都开了<?php 标签,但没有关闭?

 code> ./ Cycleworks / ContactExtended / Helper / Data.php 
<?php
class Cycleworks_ContactExtended_Helper_Data extends Mage_Core_Helper_Abstract
{

}






自定义模块中的XML:

  ./ Cycleworks / ContactExtended / etc / config.xml 
<?xml version =1.0?>
< config>
< modules>
< Cycleworks_ContactExtended>
< version> 0.0.01< / version>
< / Cycleworks_ContactExtended>
< / modules>
< frontend>
<路由器>
< contacts>
< args>
< modules>
< Cycleworks_ContactExtended before =Mage_Contacts> Cycleworks_ContactExtended< / Cycleworks_ContactExtended>
< / modules>
< / args>
< / contacts>
< / router>
< / frontend>
< global>
< helpers>
< contactextended>
< class> Cycleworks_ContactExtended_Helper< / class>
< / contactextended>
< / helpers>
< / global>
< / config>






这就是后端。对于表单本身,我将这段代码添加到了评论块下面的form.phtml,并在关闭< / ul> 标签之上。对于大多数人来说,这个文件位于 app / code / design / frontend / default / default / template / contacts 中。由于我有一个我购买的TM模板,我的是$ code> default / a034 / template / contacts

 <?php 
$ confirm_people_question =摩托车有两个这样的韵律和韵律; // CKCK form anti-spam
?>
< li>
< label for =peopleclass =required>< em> *< / em><?php echo $ confirm_people_question?>< / label>
< div class =input-box>
< input name =peopleid =peopletitle =请确认你是人value =class =required-entry input-texttype =text/>
< / div>
< / li>
<?php
//来自http://www.sharpdotinc.com/mdost/2009/04/06/magento-getting-product-attributes-values-and-labels/
$ wanted = Array(make,model,engine_size); //注意每个属性需要可搜索
$ 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>年份< / label>< br>
< select id =yearname =bike_year>
< option value =empty>< / option>
< for($ idx = date(Y); $ idx> = 1985; $ idx--)
echo< option value = \$ idx\> $ idx< / option> ; \\\
;
?>
< / select>
< / div>
< div class =ymm>
< label for =bike_make> Make< / label>< br>
< select id =makename =bike_make>
< option value =empty>< / option>
< foreach($ attributeArray ['make'] as $ id => $ brand)
echo< option value = \$ brand\> $ brand< / option> \\\
;
?>
< / select>
< / div>
< div class =ymm>
< label for =bike_model>模型< / label>< br>
< select id =modelname =bike_model>
< option value =empty>< / option>
< foreach($ attributeArray ['model'] as $ id => $ model)
echo< option value = \$ model\> $ model< / option> \\\
;
?>
< / select>
< / div>
< div class =ymm>
< label for =bike_model_ext>更多< / label>
< div class =input-box>
< input type =textsize =15value =id =model_extname =bike_model_extclass =input-text>
< / div>
< / div>
< / li>






我几乎忘了,拼图的最后一个关键是管理区域中的邮件模板:系统 - 事务电子邮件。找到您的HTML联系人模板(或制作新的模板,不要将其转换为纯文本),这就是我所得到的:

 < 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>名称< / td>< td> {{var data.name}}< / td>< / tr>
< tr>< td>电子邮件< / td>< td> {{var data.email}}< / td>< / tr>
< tr>< td>电话< / td>< td> {{var data.telephone}}< / td>< / tr>
< / table>
< P>
< fieldset>< legend>主题:& nbsp; {{var data.subject}}< / legend>
{{var data.comment}}
< / fieldset>
自行车信息:{{var data.bike_year}} {{var data.bike_make}} {{var data.bike_model}} {{var data.bike_model_ext}}
< / div>
< / body>






我从来没有想过自己会做自己的定制模块,但我遵循我在这里和其他地方找到的食谱,把它放在一起。当Capcha失败时,它也会正常运行。我试图研究如何给客户自己的联系人选择CC,但我找不到任何东西。



之后,我试图做一个自定义模块允许新订单的备用管理员通知电子邮件模板,但是我从上面学到的知识是不够的。 :P所以我对Magento的了解和安慰可能高于危险黑客,但我还有很长的路要走。


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.

解决方案

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: &nbsp; {{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.

这篇关于Magento联络表格 - 自己收到邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆