【问题标题】:Magento Contact Form - been receiving email from myselfMagento 联系表 - 收到我自己的电子邮件
【发布时间】:2012-10-10 03:06:07
【问题描述】:

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

http://i.stack.imgur.com/QsACc.jpg 这张图片显示电子邮件来自我自己

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

这真的很烦人,因为当很多人使用它时,我无法分辨哪个是哪个。

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

【问题讨论】:

    标签: forms email magento contact


    【解决方案1】:

    您是否在后端检查了您的电子邮件配置。 管理员 -> 系统 -> 配置 -> 存储电子邮件地址和 管理员 -> 系统 -> 配置 -> 联系人 -> 电子邮件选项

    【讨论】:

    • 这些用于在客户提交表单时设置目标电子邮件。我说的是在收到客户提交的电子邮件后,我看不到他们的姓名或电子邮件地址,而是显示电子邮件是我自己发送的。如果我收到客户提交的 10 封邮件,我会看到 10 封电子邮件带有相同的磁贴,全部来自“我”,如上图 2。该表格工作正常,只是我需要它在“发件人”部分而不是我的电子邮件中显示我客户的电子邮件/姓名。
    【解决方案2】:

    从技术上讲,这是Change 'From' field of magento contact form email to the sender 的副本,但我在这里给出了完整而彻底的答案。那里提供了一个简单的核心技巧。

    我决心不破解核心文件,所以我通过制作自定义控制器解决了这个问题。我读了一遍,这似乎很容易......而且市场上没有任何扩展可以提供我设定要实现的目标:1)在发件人上有客户电子邮件和姓名; 2) 用于反垃圾邮件的简单人工输入; 3) 几个自定义字段,其中 3 个实际上是产品属性。

    完成此操作的文件是:

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

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

    // 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>  
    

    其余文件进入app/code/local/。下面,我从原始控制器中复制了postAction() 函数,然后在顶部添加了我的代码,然后在-&gt;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)
                    );
                ...
                ...
                ...
        }
    }
    

    漂亮的空壳。是的,这些都有打开的&lt;?php 标签,但没有关闭标签??

    ./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>
            <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>
    

    这就是所有的后端。至于表单本身,我将此代码添加到 form.phtml 的 cmets 块下方和结束 &lt;/ul&gt; 标记上方。对于大多数人来说,这个文件位于app/code/design/frontend/default/default/template/contacts。由于我有购买的 TM 模板,所以我的在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>
    

    我差点忘记了,解开谜题的最后一个关键是管理区的邮件模板:System - Transactional Emails。找到您的 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>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>
    

    我从没想过我会制作自己的自定义模块,但我按照我在这里和其他地方找到的食谱将它们组合在一起。当验证码失败时,它也会正确运行。我确实尝试研究如何通过他们自己的联系人向客户提供抄送选项,但我找不到任何东西。

    后来,我尝试制作一个自定义模块以允许新订单的备用管理员通知电子邮件模板,但我从上面学到的知识还不够。 :P 所以我对 Magento 的了解和舒适度可能高于“危险的 hack”,但我还有很长的路要走。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-16
      • 2019-07-26
      相关资源
      最近更新 更多