After configuring your Mac's Postfix main.cnf w/ Gmail/SendGrid SMTP, e.g. using these guides:
and verifying that these mail mechanisms work:
1. Mac's mail CLI: echo "Hello World" | mail -s "Test Postfix" firstname.lastname@example.org
2. PHP mail() function: custom, non-Drupal test script w/ mail($to, $subject, $message, $headers)
you might still have problem sending mail when in Drupal site/context. It turned out that MAMP/XAMPP for Mac stacks set the DYLD_LIBRARY_PATH environment variable in their "bin/envvars" config files which causes Mac's /usr/sbin/sendmail to use the MAMP/XAMPP's bundled, mail-related libraries instead of the native ones (system default).
A quick fix is to override/unset the AMP stack's DYLD_LIBRARY_PATH using Drupal's settings.php.
- // You could put this in the site's settings.php.
- // We want to use the Mac's mail utilities instead of the MAMP/XAMPP bundled ones by
- // unsetting the DYLD_LIBRARY_PATH set by the AMP stack to revert it to system default.
- // Tip: DYLD means "DYnamic Link eDitor".