Loading...


Related Products


Date Published: November 10, 2022

Testing Sending Email Using Platform Email From Drupal and the Command Line

There are multiple ways to test whether email is sending from your environment. This assumes that you've successfully verified one or more domains, and have turned on Platform Email for the environment you're working on.

From the command line:

Note that his only tests whether your environment can send mail, not necessarily Drupal.
echo Test email | mail -s "Test email." "[email protected]" -r "[email protected]"

Using the PHP command line:

Note that this only tests whether PHP can send email, not necessarily Drupal
php -r 'mail("[email protected]", "Test email.", "Body of the email", "From: [email protected]");'

To test specifically whether Drupal can send email, see the following Drush command

Using Drush (for Drupal 7):

This requires a separate command file, though these are in the development stages:

Using Drush (for Drupal 8 or 9):

drush php-eval '$mailManager = \Drupal::service("plugin.manager.mail");
  $params["context"]["subject"] = "Test mail subject.";
  $params["context"]["message"] = "Test mail message.";
  $to = "[email protected]"; // Email address needs to be sent to
  $langcode = "en"; // Change the language code if appropriate
  $result = $mailManager->mail("system", "mail", $to, $langcode, $params);
  if ($result["result"] !== true) {
    echo t("There was a problem sending your mail and it was not sent.");
   }
   else {
     echo t("Your message has been sent.");
   }' -l your-site.com

In all the examples above, Replace [email protected] with a real recipient email address. The From address can be a no-reply address, but it must be a verified domain within the Platform Email settings. Note that the Drush example uses the site's main email address.

After running that, and receiving an email, we have instructions on how to verify the email itself was sent by Platform Email by looking the headers.

Did not find what you were looking for?

If this content did not answer your questions, try searching or contacting our support team for further assistance.

Back to Section navigation