2

I send emails from Contact form, e.g. template='contacts/form.phtml', to an osTicket system.

My problem is that the customer's email address is set as the ReplyTo header of the email sent by this form, but my osTicket system needs the customer's email set as the From header.

How could I modify the From header in the email sent from the Contact form of Magento website?

  • what you mean by form address – Amit Bera May 8 '15 at 12:35
  • I mean the header of the email – Memes May 8 '15 at 12:44
  • The "from header data" in what source specifically? Your osTicket system or Magento? I would assume Magento (where/which email?), but not sure I understand – Nick Rolando May 8 '15 at 16:22
  • I reformulated the question to be clearer...at least I hope – Memes May 8 '15 at 16:32
2

You will want to override the controller action that the form posts to. Here is Inchoo's tutorial on how to do that if you need help.

My form is posting to Mage_Contacts_IndexController::postAction. You see this code in that action method:

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

The 2nd argument of sendTransaction() is the $sender. I would rewrite this action method and change this code to:

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

If I understand your requirements correctly what you are doing is overriding the Mage_Contacts_IndexController class, with a custom module I presume. This is then instead of sending to the user it is sending to your e-mail (osTicket) for ticket tracking.

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

The above is the original section which sends the mail, so if you were to modify this to add a ->setFrom($post['email']) this should add a email header.

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

Obviously this will need to be done wherever it has been overwritten in your current setup. You might need to provide more details of how the current website is configured (ie the module that does the integration).

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.