I am developing a custom module in Drupal 8. I am trying to send an email on form submission. I installed mail client on my server and able to send email from command line in the server but when I am trying to send email from devel to test my site its not working.Its returning nothing. I tried with \Drupal\Core\Mail\Plugin\Mail\PhpMail(); and \Drupal::service('plugin.manager.mail');
$mailManager = \Drupal::service('plugin.manager.mail');
$langcode = \Drupal::currentUser()->getPreferredLangcode();
$params['context']['subject'] = 'Subject';
$params['context']['message'] = 'body';
$to = 'myorgemail@company.test';
$result['result'] = $mailManager->mail('system', 'mail', $to, $langcode, $params);
dpm($result['result']);
The other way which I tried is
$send_mail = new \Drupal\Core\Mail\Plugin\Mail\PhpMail();
$from = 'from_email_given';
$message['headers'] = array(
'content-type' => 'text/html',
'MIME-Version' => '1.0',
'reply-to' => $from,
'from' => 'sender name <'.$from.'>');
$message['to'] = 'to_email_given';
$message['subject'] = 'Subject Goes here !!!!!';
$message['body'] = 'Hello';
$send_mail->mail($message);
both the ways I am not receiving the email. I am not sure how to debug and solve this. Please ask me more information if needed.