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();

$storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;

$userSubject='test mail';

$from = [
    'name' => 'sample',
    'email' => 'from@gmail.com',

$to = [
    'email' => 'to@gmail.com',
    '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)

$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!

  • Please review this answer magento.stackexchange.com/a/180798 I hope it will work for you – Shorabh Jul 25 '18 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 Jul 25 '18 at 9:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.