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()));
        }
    }
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);
?>
2

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.