I have just installed magento 2.2.8 in XAMPP in local and run folllowing code but it throw error "unable to send mail"
then after When I changed password for customer,it throws same error
I executed php mail()
function so This php works fine and it sending mail
public function execute()
{
try {
$sender = [
'email' => "[email protected]",
'name' => "aaaa"
];
$sentToEmail = "[email protected]";
$sentToName = "bbbb";
// $this->state->setAreaCode(Area::AREA_FRONTEND);
echo "ddd";
$this->transportBuilder
->setTemplateIdentifier(self::TEST_TEMPLATE_IDENTIFIER)
->setTemplateOptions(['area' => Area::AREA_FRONTEND, 'store' => 1])
->setTemplateVars([])
->setFrom($sender)
->addTo($sentToEmail,$sentToName)
->getTransport()
->sendMessage();
// print_r(__('Everything is fine, email has been sent.'));
} catch (\Exception $e) {
echo "<pre>";print_r(__($e->getMessage()));
}
}