0

How would solve this? Magento is unable to send mail. I am on a localhost and have the Mageplaza SMTP module installed.

enter image description here

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
asked Jul 25, 2018 at 9:24
2
  • Please review this answer magento.stackexchange.com/a/180798 I hope it will work for you Commented 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. Commented Jul 25, 2018 at 9:36

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.