You are here

function yamlform_mail in YAML Form 8

Implements hook_mail().

File

./yamlform.module, line 206
Enables the creation of forms and questionnaires.

Code

function yamlform_mail($key, &$message, $params) {

  // Never send emails when using devel generate to create 1000's of
  // submissions.
  if (\Drupal::moduleHandler()
    ->moduleExists('devel_generate') && \Drupal\yamlform\Plugin\DevelGenerate\YamlFormSubmissionDevelGenerate::isGeneratingSubmissions()) {
    $message['send'] = FALSE;
  }
  $message['subject'] = $params['subject'];
  $message['body'][] = $params['body'];

  // Set the header's 'From' to the 'from_mail' so that the form's email from
  // value is used instead of site's email address.
  // See: \Drupal\Core\Mail\MailManager::mail.
  if (!empty($params['from_mail'])) {
    $message['from'] = $params['from_mail'];
    $message['headers']['From'] = $params['from_mail'];
    $message['headers']['Reply-to'] = $params['from_mail'];
    $message['headers']['Return-Path'] = $params['from_mail'];
  }
  if (!empty($params['cc_mail'])) {
    $message['headers']['Cc'] = $params['cc_mail'];
  }
  if (!empty($params['bcc_mail'])) {
    $message['headers']['Bcc'] = $params['bcc_mail'];
  }
}