To send an email using Drupal, you can use the `drupal_mail()` function. Here's a basic example of how you can send an email:
// Define the email parameters.
$module = 'your_module';
$key = 'email_key';
$to = 'recipient@example.com';
$language = language_default();
$from = 'sender@example.com';
$subject = 'Subject of the email';
$body = 'This is the body of the email message.';
// Send the email.
$send = TRUE;
$result = drupal_mail($module, $key, $to, $language, $params = array('subject' => $subject, 'body' => $body), $from, $send);Replace `'your_module'` with the machine name of your module and `'email_key'` with the key of the email template you want to use (if applicable).
Make sure you have configured the SMTP settings in your Drupal site's configuration to ensure that emails are sent successfully.
Additionally, you may want to use contributed modules like SMTP Authentication Support or SMTP module to configure SMTP settings for sending emails from your Drupal site. These modules provide more advanced configuration options and support for different email services.
Remember to replace placeholders like 'recipient@example.com', 'sender@example.com', 'Subject of the email', and 'This is the body of the email message' with actual values relevant to your email.
Always ensure that you're following best practices for sending emails, including proper formatting, validation, and avoiding spam-like behavior.
Comments