0

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()));
 }
 }
asked Aug 22, 2019 at 11:27
2

1 Answer 1

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);
?>
answered Aug 22, 2019 at 11:35
2
  • as per my question I mentioned that php mail() function works fine Commented Aug 22, 2019 at 12:05
  • please follow below link that kind of task I have done and fixed. magento.stackexchange.com/questions/279330/… Commented Aug 22, 2019 at 13:12

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.