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()));
}
}
-
reference link => magento.stackexchange.com/questions/180788/…Savan Patel– Savan Patel2019年08月22日 11:33:52 +00:00Commented Aug 22, 2019 at 11:33
-
php mail function works fineNiraj Patel– Niraj Patel2019年08月22日 12:06:23 +00:00Commented Aug 22, 2019 at 12:06
1 Answer 1
First check if your server's email is working. If its local system than you have to install SMTP module to send email.
check below code at root of magento by creating new file. and run url like: yourmagentobaseURL/yourfile.php
<?php
$to = "[email protected]";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: [email protected]" . "\r\n" .
"CC: [email protected]";
mail($to,$subject,$txt,$headers);
?>
-
as per my question I mentioned that php mail() function works fineNiraj Patel– Niraj Patel2019年08月22日 12:05:37 +00:00Commented Aug 22, 2019 at 12:05
-
please follow below link that kind of task I have done and fixed. magento.stackexchange.com/questions/279330/…Dinesh Rajput– Dinesh Rajput2019年08月22日 13:12:56 +00:00Commented Aug 22, 2019 at 13:12