How would solve this? Magento is unable to send mail. I am on a localhost and have the Mageplaza SMTP module installed.
Here is an excerpt my controller code. the $to and $from emails are actual emails (just changed it for this post)
$postObject = new \Magento\Framework\DataObject();
$postObject->setData($post);
$storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;
$userSubject='test mail';
$from = [
'name' => 'sample',
'email' => '[email protected]',
];
$to = [
'email' => '[email protected]',
'name' => 'stuff',
];
$template = "course_request";
$transport = $this->_transportBuilder
->setTemplateIdentifier($template) // email template
->setTemplateOptions( [
'area' => \Magento\Framework\App\Area::AREA_FRONTEND, \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE
'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
])
->setTemplateVars(['data' => $postObject])
->setFrom($from, $storeScope)
->addTo($to, $storeScope)
->getTransport();
$transport->sendMessage();
$this->messageManager->addSuccess(__('Email was succesfully sent!'));
I am a little new to Magento and it would help if you can explain a little. Thank you very much!
sv3n
11.7k7 gold badges44 silver badges75 bronze badges
-
Please review this answer magento.stackexchange.com/a/180798 I hope it will work for youShorabh– Shorabh2018年07月25日 09:29:20 +00:00Commented Jul 25, 2018 at 9:29
-
I forgot to mention that I'm on localhost rather than on a server. I have also read that post and sadly it has not been helpful.ralp930– ralp9302018年07月25日 09:36:35 +00:00Commented Jul 25, 2018 at 9:36
default