Hi,
I have a requirement to create a form with custom code, while submitting the form we need to trigger an email. I am using drupal 8 with custom module
I tried different codes by googling, but no luck. website is able to send email while creating user account in admin panel. I setup SMTP authentication module. Please give custom code with SMTP to send email.

Comments

A111210441 created an issue. See original summary.

cilefen’s picture

Priority: Major » Normal
Bunty Badgujar’s picture

Hi,
Use following module to send HTML emails in Drupal 8
https://www.drupal.org/project/swiftmailer

gopal6988’s picture

Hi,

Without any Contrib module, The below code works for me.

$send_mail = new \Drupal\Core\Mail\Plugin\Mail\PhpMail(); // this is used to send HTML emails
$from = ‘from@gmail.com’;
$to = ‘to@gmail.com’;
$message['headers'] = array(
'content-type' => 'text/html',
'MIME-Version' => '1.0',
'reply-to' => $from,
'from' => 'sender name <'.$from.'>'
);
$message['to'] = $to;
$message['subject'] = "Subject Goes here !!!!!";

$message['body'] = 'Hello,
Thank you for reading this blog.';

$send_mail->mail($message);

cilefen’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

itsnadeem’s picture

please see this article