1

I realize priority headers are something of the past for the most part, but I was wondering if it's possible to add additional headers (eg. Priority Flag) to an email sent from Webform (Drupal 8 version)?

Similar to this question - https://www.drupal.org/forum/support/post-installation/2013-08-29/adding-priority-flag-to-email-sent-by-webform-module

I understand this is possible with a remote post, but this is strictly for sending an email.

Any help is apprciated.

Just for context, here is how it can be set strictly in a PHP email.

$headers = "MIME-Version: 1.0\n" ;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";
$headers .= "X-Priority: 1 (Highest)\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "Importance: High\n";

$to = 'bob@email.com';
$subject = 'High Importance Email Testing';
$message = 'Testing email importance, please ignore';
$status   = mail($to, $subject, $message,$headers);

I managed to get the module working as I'd like, thanks to @jrockowitz

Here is the final module

<?php
/**
* implements hook_mail_alter()
*/
function priority_headers_mail_alter(&$message) 
{
    // only alter webforms
   if (strpos($message['id'], 'webform_email_web_requests') === 0) 
   {    
       //Get webform submission
       $webform_submission = $message['params']['webform_submission'];

       //Get the value from the priority field
       $priority = $webform_submission->getElementData('priority');

       if($priority == 'Critical')
       {
           /*setting priority headers*/
           $message['headers']['X-Priority'] = '1 (Highest)';
           $message['headers']['X-MSMail-Priority'] = 'High';
           $message['headers']['Importance'] = 'High';          
       }
   }
}
1

There is a hook for that...

hook_mail_alter()

For an example see webform_mail_alter()

  • That worked perfectly! I'm now trying to take it one step further. I'd like to check the value of a particular field (priority) and if the value is "critical" add the additional headers. I'm having difficulty accessing the values of that field. [webform_submission] => Drupal\webform\Entity\WebformSubmission Object ( [data:protected] => Array ( [priority] => Medium – B.Friddy Feb 5 '18 at 19:52
  • You may have to use WebformSubmission::getElementData or WebformSubmission::getData – jrockowitz Feb 5 '18 at 21:40
  • Thanks again jrockowitz for pointing me in the right direction. Is there a particular location / site / file to see all the available functions / methods available to Webform? (eg. getElementData) – B.Friddy Feb 6 '18 at 14:19
  • You probably need to look through the Webform module code. – mbomb007 Jun 19 '19 at 18:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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