Change 'From' field of magento contact form email to the sender

痞子三分冷 提交于 2019-11-30 14:27:20

问题


How would one go about changing the 'From' field of the contact form email to that of the sender's? For instance, if a customer was to fill in the form with the email 'test@test.com', how can I make the generated email be from 'test@test.com'?

I've looked at the 'email sender' field in the system admin panels, but this only allows for a range of preset store emails.

Many thanks


回答1:


The place where this gets sent is in app/code/core/Mage/Contacts/controllers/IndexController.php at abouts line 100. It looks like the reply-to address for the emails is already set to the email address from the post, so if you're just looking to get easier replies, I'd suggest not fooling with it.

Another issue that you'll likely see is that sending email with a spoofed "from" address may cause your site to quickly become blacklisted from many email providers, which may affect the rest of your business.

That said, if you still want to do this, in that file change this code a bit:

            $mailTemplate->setDesignConfig(array('area' => 'frontend'))
                ->setReplyTo($post['email'])
                ->sendTransactional(
                    Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
                    Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER), // change this
                    Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
                    null,
                    array('data' => $postObject)
                );

Hope that helps!

Thanks, Joe




回答2:


Magento Contact Form - been receiving email from myself is a newer duplicate of this question and Joe's answer got me on the right path. In my answer to the duplicate question, I wrote a custom module to override app/code/core/Mage/Contacts/controllers/IndexController.php and ended up changing the indicated line above to array('name'=>$post['name'], 'email'=>$post['email']), to make the fix.

IMHO, when I do urgent small fixes in the core that have to stay until properly overloaded, I'm sure to end each line with a comment with my initials twice //CKCK hack to fix ___ and then you can grep for this and see all of your mods via ssh shell: app/code/core$ grep -rn "CKCK" *

I'm also using github for version control, which helps, too.



来源:https://stackoverflow.com/questions/6188855/change-from-field-of-magento-contact-form-email-to-the-sender

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!