How to override default contact form Model file in Magento 2.2.5?main.CRITICAL: Plugin class doesn't existMagento 2: How to override newsletter Subscriber modelWhy Getting categories and names on product view page Magento 2 fails?Magento Contact Form: Unable to submit your request. Please, try again laterMagento 2: Plugin class does not existMagento offline custom Payment method with drop down listMagento 2 : override model fileHow to solve Front controller reached 100 router match iterations in magento2Magento 2.3 Can't view module's front end page output?Magento 2.3.0 - Set up multiple websites, stores, and store views

Violin - Can double stops be played when the strings are not next to each other?

Co-worker team leader wants to inject his friend's awful software into our development. What should I say to our common boss?

What are substitutions for coconut in curry?

Python if-else code style for reduced code for rounding floats

What is "focus distance lower/upper" and how is it different from depth of field?

What's wrong with this fake proof of Twin Prime Conjecture?

Why would a flight no longer considered airworthy be redirected like this?

My adviser wants to be the first author

how to write formula in word in latex

How to change two letters closest to a string and one letter immediately after a string using notepad++

Is it true that good novels will automatically sell themselves on Amazon (and so on) and there is no need for one to waste time promoting?

Is it insecure to send a password in a `curl` command?

How to write a general formula for this sequence?

How to terminate ping <dest> &

A sequence that has integer values for prime indexes only

Did Ender ever learn that he killed Stilson and/or Bonzo?

How to parse string to number while destructuring?

What is the significance behind "40 days" that often appears in the Bible?

Why is the President allowed to veto a cancellation of emergency powers?

How Could an Airship Be Repaired Mid-Flight

How can I get full line of circle of this picture?

I got the following comment from a reputed math journal. What does it mean?

Is "upgrade" the right word to use in this context?

How many ways can 200 identical balls be distributed into 40 distinct jars?



How to override default contact form Model file in Magento 2.2.5?


main.CRITICAL: Plugin class doesn't existMagento 2: How to override newsletter Subscriber modelWhy Getting categories and names on product view page Magento 2 fails?Magento Contact Form: Unable to submit your request. Please, try again laterMagento 2: Plugin class does not existMagento offline custom Payment method with drop down listMagento 2 : override model fileHow to solve Front controller reached 100 router match iterations in magento2Magento 2.3 Can't view module's front end page output?Magento 2.3.0 - Set up multiple websites, stores, and store views













1















I want to override default contact form Model file (ie, Mail.php and mailinterface.php) in Magento 2.

Struggling to override this file since the last 2days.

Any help would be appreciated.



/var/www/html/magento/app/code/Amy/Contactform/Model/Mail.php



<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformModel;

use MagentoFrameworkMailTemplateTransportBuilder;
use MagentoFrameworkTranslateInlineStateInterface;
use MagentoStoreModelStoreManagerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkAppArea;

class Mail extends MailInterface
null $storeManager
*/
public function __construct(
ConfigInterface $contactsConfig,
TransportBuilder $transportBuilder,
StateInterface $inlineTranslation,
StoreManagerInterface $storeManager = null
)
$this->contactsConfig = $contactsConfig;
$this->transportBuilder = $transportBuilder;
$this->inlineTranslation = $inlineTranslation;
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);


/**
* Send email from contact form
*
* @param string $replyTo
* @param array $variables
* @return void
*/
public function send($recipient, $replyTo, array $variables)

/** @see MagentoContactControllerIndexPost::validatedParams() */
$replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null;
if ($recipient == 'General feedback')
$emails = ['aaa@gmail.com']; // add your email list
else if ($recipient == 'Warranty')
$emails = ['bbb@gmail.com']; // add your email list


$this->inlineTranslation->suspend();
try
$transport = $this->transportBuilder
->setTemplateIdentifier($this->contactsConfig->emailTemplate())
->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
'store' => $this->storeManager->getStore()->getId()
]
)
->setTemplateVars($variables)
->setFrom($this->contactsConfig->emailSender())
->addTo($emails)
->setReplyTo($replyTo, $replyToName)
->getTransport();

$transport->sendMessage();
finally
$this->inlineTranslation->resume();





/var/www/html/magento/app/code/Amy/Contactform/Model/Mail1Interface.php



<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformModel;

/**
* Email from contact form
*
* @api
* @since 100.2.0
*/
interface Mail1Interface extends MialInterface

/**
* Send email from contact form
*
* @param string $replyTo Reply-to email address
* @param array $variables Email template variables
* @return void
* @since 100.2.0
*/
public function send($recipient, $replyTo, array $variables);



/var/www/html/magento/app/code/Amy/Contactform/Controller/Index/Post.php



<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformControllerIndex;

use MagentoContactModelConfigInterface;
use MagentoContactModelMailInterface;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkControllerResultRedirect;
use MagentoFrameworkExceptionLocalizedException;
use MagentoFrameworkHTTPPhpEnvironmentRequest;
use PsrLogLoggerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkDataObject;

class Post extends MagentoContactControllerIndexPost

/**
* @var DataPersistorInterface
*/
private $dataPersistor;

/**
* @var Context
*/
private $context;

/**
* @var MailInterface
*/
private $mail;

/**
* @var LoggerInterface
*/
private $logger;

/**
* @param Context $context
* @param ConfigInterface $contactsConfig
* @param MailInterface $mail
* @param DataPersistorInterface $dataPersistor
* @param LoggerInterface $logger
*/
public function __construct(
Context $context,
ConfigInterface $contactsConfig,
MailInterface $mail,
DataPersistorInterface $dataPersistor,
LoggerInterface $logger = null
)
parent::__construct($context, $contactsConfig, $mail, $dataPersistor);
$this->context = $context;
$this->mail = $mail;
$this->dataPersistor = $dataPersistor;
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);


/**
* Post user question
*
* @return Redirect
*/
public function execute()

if (!$this->isPostRequest())
return $this->resultRedirectFactory->create()->setPath('*/*/');

try
$this->sendEmail($this->validatedParams());
$this->messageManager->addSuccessMessage(
__('Thanks for contacting us. Your inquiry was submitted and will be responded to you as soon as possible.')
);
$this->dataPersistor->clear('contact_us');
catch (LocalizedException $e)
$this->messageManager->addErrorMessage($e->getMessage());
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());
catch (Exception $e)
$this->logger->critical($e);
$this->messageManager->addErrorMessage(
__('An error occurred while processing your form. Please try again later.')
);
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());

return $this->resultRedirectFactory->create()->setPath('contact/index');


/**
* @param array $post Post data from contact form
* @return void
*/
private function sendEmail($post)

$this->mail->send(
$post['subject'],
$post['email'],
['data' => new DataObject($post)]
);


/**
* @return bool
*/
private function isPostRequest()

/** @var Request $request */
$request = $this->getRequest();
return !empty($request->getPostValue());


/**
* @return array
* @throws Exception
*/
private function validatedParams()

$request = $this->getRequest();
if (trim($request->getParam('name')) === '')
throw new LocalizedException(__('Name is missing'));

if (trim($request->getParam('lastname')) === '')
throw new LocalizedException(__('LastName is missing'));

if (trim($request->getParam('address1')) === '')
throw new LocalizedException(__('Address1 is missing'));

if (trim($request->getParam('address2')) === '')
throw new LocalizedException(__('Address2 is missing'));

if (trim($request->getParam('city')) === '')
throw new LocalizedException(__('City is missing'));

if (trim($request->getParam('stateprovince')) === '')
throw new LocalizedException(__('State is missing'));

if (trim($request->getParam('zipcode')) === '')
throw new LocalizedException(__('Zipcode is missing'));

if (trim($request->getParam('subject')) === '')
throw new LocalizedException(__('Subject is missing'));

if (trim($request->getParam('comment')) === '')
throw new LocalizedException(__('Comment is missing'));


if (false === strpos($request->getParam('email'), '@'))
throw new LocalizedException(__('Invalid email address'));

if (trim($request->getParam('hideit')) !== '')
throw new Exception();


return $request->getParams();




/var/www/html/magento/app/code/Amy/Contactform/etc/di.xml



<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoContactBlockContactForm" type="AmyContactformBlockContactForm" />
<preference for="MagentoContactControllerIndexPost" type="AmyContactformControllerIndexPost" />
<preference for="MagentoContactModelMail" type="AmyContactformModelMail" />
</config>









share|improve this question
























  • Tried preference if so post code here @Amy

    – Prathap Gunasekaran
    yesterday











  • what function and what you want to modify

    – Amit Bera
    yesterday











  • check my update question..

    – Amy
    yesterday











  • @Amy Is any one of it working, if not go for <plugin> method to override each function with around method. I could see that you're overriding three functions in each class so better go for plugin to achieve it.

    – Prathap Gunasekaran
    yesterday












  • Is it possible to override MailInterface.php

    – Amy
    yesterday















1















I want to override default contact form Model file (ie, Mail.php and mailinterface.php) in Magento 2.

Struggling to override this file since the last 2days.

Any help would be appreciated.



/var/www/html/magento/app/code/Amy/Contactform/Model/Mail.php



<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformModel;

use MagentoFrameworkMailTemplateTransportBuilder;
use MagentoFrameworkTranslateInlineStateInterface;
use MagentoStoreModelStoreManagerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkAppArea;

class Mail extends MailInterface
null $storeManager
*/
public function __construct(
ConfigInterface $contactsConfig,
TransportBuilder $transportBuilder,
StateInterface $inlineTranslation,
StoreManagerInterface $storeManager = null
)
$this->contactsConfig = $contactsConfig;
$this->transportBuilder = $transportBuilder;
$this->inlineTranslation = $inlineTranslation;
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);


/**
* Send email from contact form
*
* @param string $replyTo
* @param array $variables
* @return void
*/
public function send($recipient, $replyTo, array $variables)

/** @see MagentoContactControllerIndexPost::validatedParams() */
$replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null;
if ($recipient == 'General feedback')
$emails = ['aaa@gmail.com']; // add your email list
else if ($recipient == 'Warranty')
$emails = ['bbb@gmail.com']; // add your email list


$this->inlineTranslation->suspend();
try
$transport = $this->transportBuilder
->setTemplateIdentifier($this->contactsConfig->emailTemplate())
->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
'store' => $this->storeManager->getStore()->getId()
]
)
->setTemplateVars($variables)
->setFrom($this->contactsConfig->emailSender())
->addTo($emails)
->setReplyTo($replyTo, $replyToName)
->getTransport();

$transport->sendMessage();
finally
$this->inlineTranslation->resume();





/var/www/html/magento/app/code/Amy/Contactform/Model/Mail1Interface.php



<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformModel;

/**
* Email from contact form
*
* @api
* @since 100.2.0
*/
interface Mail1Interface extends MialInterface

/**
* Send email from contact form
*
* @param string $replyTo Reply-to email address
* @param array $variables Email template variables
* @return void
* @since 100.2.0
*/
public function send($recipient, $replyTo, array $variables);



/var/www/html/magento/app/code/Amy/Contactform/Controller/Index/Post.php



<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformControllerIndex;

use MagentoContactModelConfigInterface;
use MagentoContactModelMailInterface;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkControllerResultRedirect;
use MagentoFrameworkExceptionLocalizedException;
use MagentoFrameworkHTTPPhpEnvironmentRequest;
use PsrLogLoggerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkDataObject;

class Post extends MagentoContactControllerIndexPost

/**
* @var DataPersistorInterface
*/
private $dataPersistor;

/**
* @var Context
*/
private $context;

/**
* @var MailInterface
*/
private $mail;

/**
* @var LoggerInterface
*/
private $logger;

/**
* @param Context $context
* @param ConfigInterface $contactsConfig
* @param MailInterface $mail
* @param DataPersistorInterface $dataPersistor
* @param LoggerInterface $logger
*/
public function __construct(
Context $context,
ConfigInterface $contactsConfig,
MailInterface $mail,
DataPersistorInterface $dataPersistor,
LoggerInterface $logger = null
)
parent::__construct($context, $contactsConfig, $mail, $dataPersistor);
$this->context = $context;
$this->mail = $mail;
$this->dataPersistor = $dataPersistor;
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);


/**
* Post user question
*
* @return Redirect
*/
public function execute()

if (!$this->isPostRequest())
return $this->resultRedirectFactory->create()->setPath('*/*/');

try
$this->sendEmail($this->validatedParams());
$this->messageManager->addSuccessMessage(
__('Thanks for contacting us. Your inquiry was submitted and will be responded to you as soon as possible.')
);
$this->dataPersistor->clear('contact_us');
catch (LocalizedException $e)
$this->messageManager->addErrorMessage($e->getMessage());
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());
catch (Exception $e)
$this->logger->critical($e);
$this->messageManager->addErrorMessage(
__('An error occurred while processing your form. Please try again later.')
);
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());

return $this->resultRedirectFactory->create()->setPath('contact/index');


/**
* @param array $post Post data from contact form
* @return void
*/
private function sendEmail($post)

$this->mail->send(
$post['subject'],
$post['email'],
['data' => new DataObject($post)]
);


/**
* @return bool
*/
private function isPostRequest()

/** @var Request $request */
$request = $this->getRequest();
return !empty($request->getPostValue());


/**
* @return array
* @throws Exception
*/
private function validatedParams()

$request = $this->getRequest();
if (trim($request->getParam('name')) === '')
throw new LocalizedException(__('Name is missing'));

if (trim($request->getParam('lastname')) === '')
throw new LocalizedException(__('LastName is missing'));

if (trim($request->getParam('address1')) === '')
throw new LocalizedException(__('Address1 is missing'));

if (trim($request->getParam('address2')) === '')
throw new LocalizedException(__('Address2 is missing'));

if (trim($request->getParam('city')) === '')
throw new LocalizedException(__('City is missing'));

if (trim($request->getParam('stateprovince')) === '')
throw new LocalizedException(__('State is missing'));

if (trim($request->getParam('zipcode')) === '')
throw new LocalizedException(__('Zipcode is missing'));

if (trim($request->getParam('subject')) === '')
throw new LocalizedException(__('Subject is missing'));

if (trim($request->getParam('comment')) === '')
throw new LocalizedException(__('Comment is missing'));


if (false === strpos($request->getParam('email'), '@'))
throw new LocalizedException(__('Invalid email address'));

if (trim($request->getParam('hideit')) !== '')
throw new Exception();


return $request->getParams();




/var/www/html/magento/app/code/Amy/Contactform/etc/di.xml



<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoContactBlockContactForm" type="AmyContactformBlockContactForm" />
<preference for="MagentoContactControllerIndexPost" type="AmyContactformControllerIndexPost" />
<preference for="MagentoContactModelMail" type="AmyContactformModelMail" />
</config>









share|improve this question
























  • Tried preference if so post code here @Amy

    – Prathap Gunasekaran
    yesterday











  • what function and what you want to modify

    – Amit Bera
    yesterday











  • check my update question..

    – Amy
    yesterday











  • @Amy Is any one of it working, if not go for <plugin> method to override each function with around method. I could see that you're overriding three functions in each class so better go for plugin to achieve it.

    – Prathap Gunasekaran
    yesterday












  • Is it possible to override MailInterface.php

    – Amy
    yesterday













1












1








1








I want to override default contact form Model file (ie, Mail.php and mailinterface.php) in Magento 2.

Struggling to override this file since the last 2days.

Any help would be appreciated.



/var/www/html/magento/app/code/Amy/Contactform/Model/Mail.php



<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformModel;

use MagentoFrameworkMailTemplateTransportBuilder;
use MagentoFrameworkTranslateInlineStateInterface;
use MagentoStoreModelStoreManagerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkAppArea;

class Mail extends MailInterface
null $storeManager
*/
public function __construct(
ConfigInterface $contactsConfig,
TransportBuilder $transportBuilder,
StateInterface $inlineTranslation,
StoreManagerInterface $storeManager = null
)
$this->contactsConfig = $contactsConfig;
$this->transportBuilder = $transportBuilder;
$this->inlineTranslation = $inlineTranslation;
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);


/**
* Send email from contact form
*
* @param string $replyTo
* @param array $variables
* @return void
*/
public function send($recipient, $replyTo, array $variables)

/** @see MagentoContactControllerIndexPost::validatedParams() */
$replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null;
if ($recipient == 'General feedback')
$emails = ['aaa@gmail.com']; // add your email list
else if ($recipient == 'Warranty')
$emails = ['bbb@gmail.com']; // add your email list


$this->inlineTranslation->suspend();
try
$transport = $this->transportBuilder
->setTemplateIdentifier($this->contactsConfig->emailTemplate())
->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
'store' => $this->storeManager->getStore()->getId()
]
)
->setTemplateVars($variables)
->setFrom($this->contactsConfig->emailSender())
->addTo($emails)
->setReplyTo($replyTo, $replyToName)
->getTransport();

$transport->sendMessage();
finally
$this->inlineTranslation->resume();





/var/www/html/magento/app/code/Amy/Contactform/Model/Mail1Interface.php



<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformModel;

/**
* Email from contact form
*
* @api
* @since 100.2.0
*/
interface Mail1Interface extends MialInterface

/**
* Send email from contact form
*
* @param string $replyTo Reply-to email address
* @param array $variables Email template variables
* @return void
* @since 100.2.0
*/
public function send($recipient, $replyTo, array $variables);



/var/www/html/magento/app/code/Amy/Contactform/Controller/Index/Post.php



<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformControllerIndex;

use MagentoContactModelConfigInterface;
use MagentoContactModelMailInterface;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkControllerResultRedirect;
use MagentoFrameworkExceptionLocalizedException;
use MagentoFrameworkHTTPPhpEnvironmentRequest;
use PsrLogLoggerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkDataObject;

class Post extends MagentoContactControllerIndexPost

/**
* @var DataPersistorInterface
*/
private $dataPersistor;

/**
* @var Context
*/
private $context;

/**
* @var MailInterface
*/
private $mail;

/**
* @var LoggerInterface
*/
private $logger;

/**
* @param Context $context
* @param ConfigInterface $contactsConfig
* @param MailInterface $mail
* @param DataPersistorInterface $dataPersistor
* @param LoggerInterface $logger
*/
public function __construct(
Context $context,
ConfigInterface $contactsConfig,
MailInterface $mail,
DataPersistorInterface $dataPersistor,
LoggerInterface $logger = null
)
parent::__construct($context, $contactsConfig, $mail, $dataPersistor);
$this->context = $context;
$this->mail = $mail;
$this->dataPersistor = $dataPersistor;
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);


/**
* Post user question
*
* @return Redirect
*/
public function execute()

if (!$this->isPostRequest())
return $this->resultRedirectFactory->create()->setPath('*/*/');

try
$this->sendEmail($this->validatedParams());
$this->messageManager->addSuccessMessage(
__('Thanks for contacting us. Your inquiry was submitted and will be responded to you as soon as possible.')
);
$this->dataPersistor->clear('contact_us');
catch (LocalizedException $e)
$this->messageManager->addErrorMessage($e->getMessage());
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());
catch (Exception $e)
$this->logger->critical($e);
$this->messageManager->addErrorMessage(
__('An error occurred while processing your form. Please try again later.')
);
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());

return $this->resultRedirectFactory->create()->setPath('contact/index');


/**
* @param array $post Post data from contact form
* @return void
*/
private function sendEmail($post)

$this->mail->send(
$post['subject'],
$post['email'],
['data' => new DataObject($post)]
);


/**
* @return bool
*/
private function isPostRequest()

/** @var Request $request */
$request = $this->getRequest();
return !empty($request->getPostValue());


/**
* @return array
* @throws Exception
*/
private function validatedParams()

$request = $this->getRequest();
if (trim($request->getParam('name')) === '')
throw new LocalizedException(__('Name is missing'));

if (trim($request->getParam('lastname')) === '')
throw new LocalizedException(__('LastName is missing'));

if (trim($request->getParam('address1')) === '')
throw new LocalizedException(__('Address1 is missing'));

if (trim($request->getParam('address2')) === '')
throw new LocalizedException(__('Address2 is missing'));

if (trim($request->getParam('city')) === '')
throw new LocalizedException(__('City is missing'));

if (trim($request->getParam('stateprovince')) === '')
throw new LocalizedException(__('State is missing'));

if (trim($request->getParam('zipcode')) === '')
throw new LocalizedException(__('Zipcode is missing'));

if (trim($request->getParam('subject')) === '')
throw new LocalizedException(__('Subject is missing'));

if (trim($request->getParam('comment')) === '')
throw new LocalizedException(__('Comment is missing'));


if (false === strpos($request->getParam('email'), '@'))
throw new LocalizedException(__('Invalid email address'));

if (trim($request->getParam('hideit')) !== '')
throw new Exception();


return $request->getParams();




/var/www/html/magento/app/code/Amy/Contactform/etc/di.xml



<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoContactBlockContactForm" type="AmyContactformBlockContactForm" />
<preference for="MagentoContactControllerIndexPost" type="AmyContactformControllerIndexPost" />
<preference for="MagentoContactModelMail" type="AmyContactformModelMail" />
</config>









share|improve this question
















I want to override default contact form Model file (ie, Mail.php and mailinterface.php) in Magento 2.

Struggling to override this file since the last 2days.

Any help would be appreciated.



/var/www/html/magento/app/code/Amy/Contactform/Model/Mail.php



<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformModel;

use MagentoFrameworkMailTemplateTransportBuilder;
use MagentoFrameworkTranslateInlineStateInterface;
use MagentoStoreModelStoreManagerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkAppArea;

class Mail extends MailInterface
null $storeManager
*/
public function __construct(
ConfigInterface $contactsConfig,
TransportBuilder $transportBuilder,
StateInterface $inlineTranslation,
StoreManagerInterface $storeManager = null
)
$this->contactsConfig = $contactsConfig;
$this->transportBuilder = $transportBuilder;
$this->inlineTranslation = $inlineTranslation;
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);


/**
* Send email from contact form
*
* @param string $replyTo
* @param array $variables
* @return void
*/
public function send($recipient, $replyTo, array $variables)

/** @see MagentoContactControllerIndexPost::validatedParams() */
$replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null;
if ($recipient == 'General feedback')
$emails = ['aaa@gmail.com']; // add your email list
else if ($recipient == 'Warranty')
$emails = ['bbb@gmail.com']; // add your email list


$this->inlineTranslation->suspend();
try
$transport = $this->transportBuilder
->setTemplateIdentifier($this->contactsConfig->emailTemplate())
->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
'store' => $this->storeManager->getStore()->getId()
]
)
->setTemplateVars($variables)
->setFrom($this->contactsConfig->emailSender())
->addTo($emails)
->setReplyTo($replyTo, $replyToName)
->getTransport();

$transport->sendMessage();
finally
$this->inlineTranslation->resume();





/var/www/html/magento/app/code/Amy/Contactform/Model/Mail1Interface.php



<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformModel;

/**
* Email from contact form
*
* @api
* @since 100.2.0
*/
interface Mail1Interface extends MialInterface

/**
* Send email from contact form
*
* @param string $replyTo Reply-to email address
* @param array $variables Email template variables
* @return void
* @since 100.2.0
*/
public function send($recipient, $replyTo, array $variables);



/var/www/html/magento/app/code/Amy/Contactform/Controller/Index/Post.php



<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformControllerIndex;

use MagentoContactModelConfigInterface;
use MagentoContactModelMailInterface;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkControllerResultRedirect;
use MagentoFrameworkExceptionLocalizedException;
use MagentoFrameworkHTTPPhpEnvironmentRequest;
use PsrLogLoggerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkDataObject;

class Post extends MagentoContactControllerIndexPost

/**
* @var DataPersistorInterface
*/
private $dataPersistor;

/**
* @var Context
*/
private $context;

/**
* @var MailInterface
*/
private $mail;

/**
* @var LoggerInterface
*/
private $logger;

/**
* @param Context $context
* @param ConfigInterface $contactsConfig
* @param MailInterface $mail
* @param DataPersistorInterface $dataPersistor
* @param LoggerInterface $logger
*/
public function __construct(
Context $context,
ConfigInterface $contactsConfig,
MailInterface $mail,
DataPersistorInterface $dataPersistor,
LoggerInterface $logger = null
)
parent::__construct($context, $contactsConfig, $mail, $dataPersistor);
$this->context = $context;
$this->mail = $mail;
$this->dataPersistor = $dataPersistor;
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);


/**
* Post user question
*
* @return Redirect
*/
public function execute()

if (!$this->isPostRequest())
return $this->resultRedirectFactory->create()->setPath('*/*/');

try
$this->sendEmail($this->validatedParams());
$this->messageManager->addSuccessMessage(
__('Thanks for contacting us. Your inquiry was submitted and will be responded to you as soon as possible.')
);
$this->dataPersistor->clear('contact_us');
catch (LocalizedException $e)
$this->messageManager->addErrorMessage($e->getMessage());
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());
catch (Exception $e)
$this->logger->critical($e);
$this->messageManager->addErrorMessage(
__('An error occurred while processing your form. Please try again later.')
);
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());

return $this->resultRedirectFactory->create()->setPath('contact/index');


/**
* @param array $post Post data from contact form
* @return void
*/
private function sendEmail($post)

$this->mail->send(
$post['subject'],
$post['email'],
['data' => new DataObject($post)]
);


/**
* @return bool
*/
private function isPostRequest()

/** @var Request $request */
$request = $this->getRequest();
return !empty($request->getPostValue());


/**
* @return array
* @throws Exception
*/
private function validatedParams()

$request = $this->getRequest();
if (trim($request->getParam('name')) === '')
throw new LocalizedException(__('Name is missing'));

if (trim($request->getParam('lastname')) === '')
throw new LocalizedException(__('LastName is missing'));

if (trim($request->getParam('address1')) === '')
throw new LocalizedException(__('Address1 is missing'));

if (trim($request->getParam('address2')) === '')
throw new LocalizedException(__('Address2 is missing'));

if (trim($request->getParam('city')) === '')
throw new LocalizedException(__('City is missing'));

if (trim($request->getParam('stateprovince')) === '')
throw new LocalizedException(__('State is missing'));

if (trim($request->getParam('zipcode')) === '')
throw new LocalizedException(__('Zipcode is missing'));

if (trim($request->getParam('subject')) === '')
throw new LocalizedException(__('Subject is missing'));

if (trim($request->getParam('comment')) === '')
throw new LocalizedException(__('Comment is missing'));


if (false === strpos($request->getParam('email'), '@'))
throw new LocalizedException(__('Invalid email address'));

if (trim($request->getParam('hideit')) !== '')
throw new Exception();


return $request->getParams();




/var/www/html/magento/app/code/Amy/Contactform/etc/di.xml



<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoContactBlockContactForm" type="AmyContactformBlockContactForm" />
<preference for="MagentoContactControllerIndexPost" type="AmyContactformControllerIndexPost" />
<preference for="MagentoContactModelMail" type="AmyContactformModelMail" />
</config>






magento2 contact-form override-model






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday







Amy

















asked yesterday









AmyAmy

3029




3029












  • Tried preference if so post code here @Amy

    – Prathap Gunasekaran
    yesterday











  • what function and what you want to modify

    – Amit Bera
    yesterday











  • check my update question..

    – Amy
    yesterday











  • @Amy Is any one of it working, if not go for <plugin> method to override each function with around method. I could see that you're overriding three functions in each class so better go for plugin to achieve it.

    – Prathap Gunasekaran
    yesterday












  • Is it possible to override MailInterface.php

    – Amy
    yesterday

















  • Tried preference if so post code here @Amy

    – Prathap Gunasekaran
    yesterday











  • what function and what you want to modify

    – Amit Bera
    yesterday











  • check my update question..

    – Amy
    yesterday











  • @Amy Is any one of it working, if not go for <plugin> method to override each function with around method. I could see that you're overriding three functions in each class so better go for plugin to achieve it.

    – Prathap Gunasekaran
    yesterday












  • Is it possible to override MailInterface.php

    – Amy
    yesterday
















Tried preference if so post code here @Amy

– Prathap Gunasekaran
yesterday





Tried preference if so post code here @Amy

– Prathap Gunasekaran
yesterday













what function and what you want to modify

– Amit Bera
yesterday





what function and what you want to modify

– Amit Bera
yesterday













check my update question..

– Amy
yesterday





check my update question..

– Amy
yesterday













@Amy Is any one of it working, if not go for <plugin> method to override each function with around method. I could see that you're overriding three functions in each class so better go for plugin to achieve it.

– Prathap Gunasekaran
yesterday






@Amy Is any one of it working, if not go for <plugin> method to override each function with around method. I could see that you're overriding three functions in each class so better go for plugin to achieve it.

– Prathap Gunasekaran
yesterday














Is it possible to override MailInterface.php

– Amy
yesterday





Is it possible to override MailInterface.php

– Amy
yesterday










3 Answers
3






active

oldest

votes


















1














Have you tried the preference as below :



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoContactModelMail" type="VendorNameModuleNameModelMail" />
</config>





share|improve this answer

























  • I have tried it, not working..

    – Amy
    yesterday


















0














After struggling for days, I got the solution
This is how you will be able to override the contact Model Mail.php file,
I posted this answer, because it may be useful to others.



<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformModel;

use MagentoFrameworkMailTemplateTransportBuilder;
use MagentoFrameworkTranslateInlineStateInterface;
use MagentoStoreModelStoreManagerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkAppArea;
use MagentoContactModelConfigInterface;

class Mail extends MagentoContactModelMail implements MagentoContactModelMailInterface
null $storeManager
*/
public function __construct(
ConfigInterface $contactsConfig,
TransportBuilder $transportBuilder,
StateInterface $inlineTranslation,
StoreManagerInterface $storeManager = null
)
$this->contactsConfig = $contactsConfig;
$this->transportBuilder = $transportBuilder;
$this->inlineTranslation = $inlineTranslation;
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);


/**
* Send email from contact form
*
* @param string $replyTo
* @param array $variables
* @return void
*/
public function send($recipient, $replyTo, array $variables)

/** @see MagentoContactControllerIndexPost::validatedParams() */
$replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null;
if ($recipient == 'General feedback')
$emails = ['aaa@gmail.com']; // add your email list
else if ($recipient == 'Warranty')
$emails = ['bbb@gmail.com']; // add your email list


$this->inlineTranslation->suspend();
try
$transport = $this->transportBuilder
->setTemplateIdentifier($this->contactsConfig->emailTemplate())
->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
'store' => $this->storeManager->getStore()->getId()
]
)
->setTemplateVars($variables)
->setFrom($this->contactsConfig->emailSender())
->addTo($emails)
->setReplyTo($replyTo, $replyToName)
->getTransport();

$transport->sendMessage();
finally
$this->inlineTranslation->resume();








share|improve this answer






























    -1














    Mailinterface.php model is an interface class and we can't directly override magento's core interfaces. You can override Mail.php using preference like :



    <preference for="MagentoContactModelMail" type="NamespaceModulenameModelMailOverride"/>


    Thanks






    share|improve this answer






















      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "479"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f266073%2fhow-to-override-default-contact-form-model-file-in-magento-2-2-5%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      Have you tried the preference as below :



      <?xml version="1.0"?>
      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
      <preference for="MagentoContactModelMail" type="VendorNameModuleNameModelMail" />
      </config>





      share|improve this answer

























      • I have tried it, not working..

        – Amy
        yesterday















      1














      Have you tried the preference as below :



      <?xml version="1.0"?>
      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
      <preference for="MagentoContactModelMail" type="VendorNameModuleNameModelMail" />
      </config>





      share|improve this answer

























      • I have tried it, not working..

        – Amy
        yesterday













      1












      1








      1







      Have you tried the preference as below :



      <?xml version="1.0"?>
      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
      <preference for="MagentoContactModelMail" type="VendorNameModuleNameModelMail" />
      </config>





      share|improve this answer















      Have you tried the preference as below :



      <?xml version="1.0"?>
      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
      <preference for="MagentoContactModelMail" type="VendorNameModuleNameModelMail" />
      </config>






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited yesterday

























      answered yesterday









      Amit NaraniwalAmit Naraniwal

      911411




      911411












      • I have tried it, not working..

        – Amy
        yesterday

















      • I have tried it, not working..

        – Amy
        yesterday
















      I have tried it, not working..

      – Amy
      yesterday





      I have tried it, not working..

      – Amy
      yesterday













      0














      After struggling for days, I got the solution
      This is how you will be able to override the contact Model Mail.php file,
      I posted this answer, because it may be useful to others.



      <?php
      /**
      * Copyright © Magento, Inc. All rights reserved.
      * See COPYING.txt for license details.
      */
      namespace AmyContactformModel;

      use MagentoFrameworkMailTemplateTransportBuilder;
      use MagentoFrameworkTranslateInlineStateInterface;
      use MagentoStoreModelStoreManagerInterface;
      use MagentoFrameworkAppObjectManager;
      use MagentoFrameworkAppArea;
      use MagentoContactModelConfigInterface;

      class Mail extends MagentoContactModelMail implements MagentoContactModelMailInterface
      null $storeManager
      */
      public function __construct(
      ConfigInterface $contactsConfig,
      TransportBuilder $transportBuilder,
      StateInterface $inlineTranslation,
      StoreManagerInterface $storeManager = null
      )
      $this->contactsConfig = $contactsConfig;
      $this->transportBuilder = $transportBuilder;
      $this->inlineTranslation = $inlineTranslation;
      $this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);


      /**
      * Send email from contact form
      *
      * @param string $replyTo
      * @param array $variables
      * @return void
      */
      public function send($recipient, $replyTo, array $variables)

      /** @see MagentoContactControllerIndexPost::validatedParams() */
      $replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null;
      if ($recipient == 'General feedback')
      $emails = ['aaa@gmail.com']; // add your email list
      else if ($recipient == 'Warranty')
      $emails = ['bbb@gmail.com']; // add your email list


      $this->inlineTranslation->suspend();
      try
      $transport = $this->transportBuilder
      ->setTemplateIdentifier($this->contactsConfig->emailTemplate())
      ->setTemplateOptions(
      [
      'area' => Area::AREA_FRONTEND,
      'store' => $this->storeManager->getStore()->getId()
      ]
      )
      ->setTemplateVars($variables)
      ->setFrom($this->contactsConfig->emailSender())
      ->addTo($emails)
      ->setReplyTo($replyTo, $replyToName)
      ->getTransport();

      $transport->sendMessage();
      finally
      $this->inlineTranslation->resume();








      share|improve this answer



























        0














        After struggling for days, I got the solution
        This is how you will be able to override the contact Model Mail.php file,
        I posted this answer, because it may be useful to others.



        <?php
        /**
        * Copyright © Magento, Inc. All rights reserved.
        * See COPYING.txt for license details.
        */
        namespace AmyContactformModel;

        use MagentoFrameworkMailTemplateTransportBuilder;
        use MagentoFrameworkTranslateInlineStateInterface;
        use MagentoStoreModelStoreManagerInterface;
        use MagentoFrameworkAppObjectManager;
        use MagentoFrameworkAppArea;
        use MagentoContactModelConfigInterface;

        class Mail extends MagentoContactModelMail implements MagentoContactModelMailInterface
        null $storeManager
        */
        public function __construct(
        ConfigInterface $contactsConfig,
        TransportBuilder $transportBuilder,
        StateInterface $inlineTranslation,
        StoreManagerInterface $storeManager = null
        )
        $this->contactsConfig = $contactsConfig;
        $this->transportBuilder = $transportBuilder;
        $this->inlineTranslation = $inlineTranslation;
        $this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);


        /**
        * Send email from contact form
        *
        * @param string $replyTo
        * @param array $variables
        * @return void
        */
        public function send($recipient, $replyTo, array $variables)

        /** @see MagentoContactControllerIndexPost::validatedParams() */
        $replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null;
        if ($recipient == 'General feedback')
        $emails = ['aaa@gmail.com']; // add your email list
        else if ($recipient == 'Warranty')
        $emails = ['bbb@gmail.com']; // add your email list


        $this->inlineTranslation->suspend();
        try
        $transport = $this->transportBuilder
        ->setTemplateIdentifier($this->contactsConfig->emailTemplate())
        ->setTemplateOptions(
        [
        'area' => Area::AREA_FRONTEND,
        'store' => $this->storeManager->getStore()->getId()
        ]
        )
        ->setTemplateVars($variables)
        ->setFrom($this->contactsConfig->emailSender())
        ->addTo($emails)
        ->setReplyTo($replyTo, $replyToName)
        ->getTransport();

        $transport->sendMessage();
        finally
        $this->inlineTranslation->resume();








        share|improve this answer

























          0












          0








          0







          After struggling for days, I got the solution
          This is how you will be able to override the contact Model Mail.php file,
          I posted this answer, because it may be useful to others.



          <?php
          /**
          * Copyright © Magento, Inc. All rights reserved.
          * See COPYING.txt for license details.
          */
          namespace AmyContactformModel;

          use MagentoFrameworkMailTemplateTransportBuilder;
          use MagentoFrameworkTranslateInlineStateInterface;
          use MagentoStoreModelStoreManagerInterface;
          use MagentoFrameworkAppObjectManager;
          use MagentoFrameworkAppArea;
          use MagentoContactModelConfigInterface;

          class Mail extends MagentoContactModelMail implements MagentoContactModelMailInterface
          null $storeManager
          */
          public function __construct(
          ConfigInterface $contactsConfig,
          TransportBuilder $transportBuilder,
          StateInterface $inlineTranslation,
          StoreManagerInterface $storeManager = null
          )
          $this->contactsConfig = $contactsConfig;
          $this->transportBuilder = $transportBuilder;
          $this->inlineTranslation = $inlineTranslation;
          $this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);


          /**
          * Send email from contact form
          *
          * @param string $replyTo
          * @param array $variables
          * @return void
          */
          public function send($recipient, $replyTo, array $variables)

          /** @see MagentoContactControllerIndexPost::validatedParams() */
          $replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null;
          if ($recipient == 'General feedback')
          $emails = ['aaa@gmail.com']; // add your email list
          else if ($recipient == 'Warranty')
          $emails = ['bbb@gmail.com']; // add your email list


          $this->inlineTranslation->suspend();
          try
          $transport = $this->transportBuilder
          ->setTemplateIdentifier($this->contactsConfig->emailTemplate())
          ->setTemplateOptions(
          [
          'area' => Area::AREA_FRONTEND,
          'store' => $this->storeManager->getStore()->getId()
          ]
          )
          ->setTemplateVars($variables)
          ->setFrom($this->contactsConfig->emailSender())
          ->addTo($emails)
          ->setReplyTo($replyTo, $replyToName)
          ->getTransport();

          $transport->sendMessage();
          finally
          $this->inlineTranslation->resume();








          share|improve this answer













          After struggling for days, I got the solution
          This is how you will be able to override the contact Model Mail.php file,
          I posted this answer, because it may be useful to others.



          <?php
          /**
          * Copyright © Magento, Inc. All rights reserved.
          * See COPYING.txt for license details.
          */
          namespace AmyContactformModel;

          use MagentoFrameworkMailTemplateTransportBuilder;
          use MagentoFrameworkTranslateInlineStateInterface;
          use MagentoStoreModelStoreManagerInterface;
          use MagentoFrameworkAppObjectManager;
          use MagentoFrameworkAppArea;
          use MagentoContactModelConfigInterface;

          class Mail extends MagentoContactModelMail implements MagentoContactModelMailInterface
          null $storeManager
          */
          public function __construct(
          ConfigInterface $contactsConfig,
          TransportBuilder $transportBuilder,
          StateInterface $inlineTranslation,
          StoreManagerInterface $storeManager = null
          )
          $this->contactsConfig = $contactsConfig;
          $this->transportBuilder = $transportBuilder;
          $this->inlineTranslation = $inlineTranslation;
          $this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);


          /**
          * Send email from contact form
          *
          * @param string $replyTo
          * @param array $variables
          * @return void
          */
          public function send($recipient, $replyTo, array $variables)

          /** @see MagentoContactControllerIndexPost::validatedParams() */
          $replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null;
          if ($recipient == 'General feedback')
          $emails = ['aaa@gmail.com']; // add your email list
          else if ($recipient == 'Warranty')
          $emails = ['bbb@gmail.com']; // add your email list


          $this->inlineTranslation->suspend();
          try
          $transport = $this->transportBuilder
          ->setTemplateIdentifier($this->contactsConfig->emailTemplate())
          ->setTemplateOptions(
          [
          'area' => Area::AREA_FRONTEND,
          'store' => $this->storeManager->getStore()->getId()
          ]
          )
          ->setTemplateVars($variables)
          ->setFrom($this->contactsConfig->emailSender())
          ->addTo($emails)
          ->setReplyTo($replyTo, $replyToName)
          ->getTransport();

          $transport->sendMessage();
          finally
          $this->inlineTranslation->resume();









          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 4 hours ago









          AmyAmy

          3029




          3029





















              -1














              Mailinterface.php model is an interface class and we can't directly override magento's core interfaces. You can override Mail.php using preference like :



              <preference for="MagentoContactModelMail" type="NamespaceModulenameModelMailOverride"/>


              Thanks






              share|improve this answer



























                -1














                Mailinterface.php model is an interface class and we can't directly override magento's core interfaces. You can override Mail.php using preference like :



                <preference for="MagentoContactModelMail" type="NamespaceModulenameModelMailOverride"/>


                Thanks






                share|improve this answer

























                  -1












                  -1








                  -1







                  Mailinterface.php model is an interface class and we can't directly override magento's core interfaces. You can override Mail.php using preference like :



                  <preference for="MagentoContactModelMail" type="NamespaceModulenameModelMailOverride"/>


                  Thanks






                  share|improve this answer













                  Mailinterface.php model is an interface class and we can't directly override magento's core interfaces. You can override Mail.php using preference like :



                  <preference for="MagentoContactModelMail" type="NamespaceModulenameModelMailOverride"/>


                  Thanks







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered yesterday









                  Hardik PatelHardik Patel

                  505314




                  505314



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Magento Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f266073%2fhow-to-override-default-contact-form-model-file-in-magento-2-2-5%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Masuk log Menu navigasi

                      Identifying “long and narrow” polygons in with PostGISlength and width of polygonWhy postgis st_overlaps reports Qgis' “avoid intersections” generated polygon as overlapping with others?Adjusting polygons to boundary and filling holesDrawing polygons with fixed area?How to remove spikes in Polygons with PostGISDeleting sliver polygons after difference operation in QGIS?Snapping boundaries in PostGISSplit polygon into parts adding attributes based on underlying polygon in QGISSplitting overlap between polygons and assign to nearest polygon using PostGIS?Expanding polygons and clipping at midpoint?Removing Intersection of Buffers in Same Layers

                      Старые Смолеговицы Содержание История | География | Демография | Достопримечательности | Примечания | НавигацияHGЯOLHGЯOL41 206 832 01641 606 406 141Административно-территориальное деление Ленинградской области«Переписная оброчная книга Водской пятины 1500 года», С. 793«Карта Ингерманландии: Ивангорода, Яма, Копорья, Нотеборга», по материалам 1676 г.«Генеральная карта провинции Ингерманландии» Э. Белинга и А. Андерсина, 1704 г., составлена по материалам 1678 г.«Географический чертёж над Ижорскою землей со своими городами» Адриана Шонбека 1705 г.Новая и достоверная всей Ингерманландии ланткарта. Грав. А. Ростовцев. СПб., 1727 г.Топографическая карта Санкт-Петербургской губернии. 5-и верстка. Шуберт. 1834 г.Описание Санкт-Петербургской губернии по уездам и станамСпецкарта западной части России Ф. Ф. Шуберта. 1844 г.Алфавитный список селений по уездам и станам С.-Петербургской губернииСписки населённых мест Российской Империи, составленные и издаваемые центральным статистическим комитетом министерства внутренних дел. XXXVII. Санкт-Петербургская губерния. По состоянию на 1862 год. СПб. 1864. С. 203Материалы по статистике народного хозяйства в С.-Петербургской губернии. Вып. IX. Частновладельческое хозяйство в Ямбургском уезде. СПб, 1888, С. 146, С. 2, 7, 54Положение о гербе муниципального образования Курское сельское поселениеСправочник истории административно-территориального деления Ленинградской области.Топографическая карта Ленинградской области, квадрат О-35-23-В (Хотыницы), 1930 г.АрхивированоАдминистративно-территориальное деление Ленинградской области. — Л., 1933, С. 27, 198АрхивированоАдминистративно-экономический справочник по Ленинградской области. — Л., 1936, с. 219АрхивированоАдминистративно-территориальное деление Ленинградской области. — Л., 1966, с. 175АрхивированоАдминистративно-территориальное деление Ленинградской области. — Лениздат, 1973, С. 180АрхивированоАдминистративно-территориальное деление Ленинградской области. — Лениздат, 1990, ISBN 5-289-00612-5, С. 38АрхивированоАдминистративно-территориальное деление Ленинградской области. — СПб., 2007, с. 60АрхивированоКоряков Юрий База данных «Этно-языковой состав населённых пунктов России». Ленинградская область.Административно-территориальное деление Ленинградской области. — СПб, 1997, ISBN 5-86153-055-6, С. 41АрхивированоКультовый комплекс Старые Смолеговицы // Электронная энциклопедия ЭрмитажаПроблемы выявления, изучения и сохранения культовых комплексов с каменными крестами: по материалам работ 2016-2017 гг. в Ленинградской области