Answers.Body: <p>I've put up a PR at <a href="https://github.com/civicrm/civicrm-core/pull/30172" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/pull/30172</a>. It worked for me. Can you confirm it also fixes it for you?</p>
  <p>Just on line 208 of CRM/Utils/Mail.php, change</p>
  <p><code>$result = $mailer-&gt;send($to, $headers, $message);</code></p>
  <p>to</p>
  <p><code>$result = $mailer-&gt;send($to, $headers, $message ?? '');</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-05-14T21:35:32.777Z
Answers.Text: Yes, it's fixed. I wouldn't do the null check inside the send call though, probably inside setEmailHeaders.
Answers.UserDisplayName: Jan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-05-12T02:35:59.343Z
Answers.LastActivityDate: 2024-05-12T02:35:59.343Z
Answers.UserDisplayName: Demerit
Body: <p>I am getting the above error message when trying to send a quick email to less then 50 contacts via extended search. I setup the outgoing email as SMTP + sender address and was able to send a test email. I didn't configure any crons yet because I thought that was only required for CiviMail but maybe I'm wrong. Any help appreciated...</p>
  <p>Stacktrace top:</p>
  <pre><code>[error] Mailing error: #0 /opt/drupal/vendor/pear/pear-core-minimal/src/PEAR.php(945): CRM_Core_Error::exceptionHandler(Object(PEAR_Error))
  #1 /opt/drupal/vendor/pear/pear-core-minimal/src/PEAR.php(577): PEAR_Error-&gt;__construct('Expected a stri...', NULL, 16, Array, NULL)
  #2 /opt/drupal/vendor/pear/pear-core-minimal/src/PEAR.php(236): PEAR::_raiseError(NULL, 'Expected a stri...')
  #3 /opt/drupal/vendor/pear/net_smtp/Net/SMTP.php(1220): PEAR::__callStatic('raiseError', Array)
  #4 /opt/drupal/vendor/pear/mail/Mail/smtp.php(391): Net_SMTP-&gt;data(NULL, 'MIME-Version: 1...')
  #5 /opt/drupal/vendor/pear/mail/Mail/smtp.php(319): Mail_smtp-&gt;send_or_fail(Array, Array, NULL)
  #6 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Utils/Mail/FilteredPearMailer.php(77): Mail_smtp-&gt;send(Array, Array, NULL)
  #7 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Utils/Mail.php(208): CRM_Utils_Mail_FilteredPearMailer-&gt;send(Array, Array, NULL)
  #8 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Contact/Form/Task/EmailTrait.php(934): CRM_Utils_Mail::send(Array)
  #9 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Contact/Form/Task/EmailTrait.php(797): CRM_Contact_Form_Task_Email-&gt;sendMessage('&quot;CiviCRM&quot; &lt;vern...', '5', 'Test', '', '', 'jan.ciriack@pos...', 539, Array, '', '')
  #10 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Contact/Form/Task/EmailTrait.php(388): CRM_Contact_Form_Task_Email-&gt;sendEmail('', '', '&quot;CiviCRM&quot; &lt;vern...', Array, '', '', '', NULL, NULL)
  #11 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Contact/Form/Task/EmailTrait.php(336): CRM_Contact_Form_Task_Email-&gt;submit(Array)
  #12 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Core/Form.php(646): CRM_Contact_Form_Task_Email-&gt;postProcess()
  #13 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Core/QuickForm/Action/Upload.php(153): CRM_Core_Form-&gt;mainProcess()
  #14 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Core/QuickForm/Action/Upload.php(120): CRM_Core_QuickForm_Action_Upload-&gt;realPerform(Object(CRM_Contact_Form_Task_Email), 'upload')
  #15 /opt/drupal/vendor/civicrm/civicrm-packages/HTML/QuickForm/Controller.php(203): CRM_Core_QuickForm_Action_Upload-&gt;perform(Object(CRM_Contact_Form_Task_Email), 'upload')
  #16 /opt/drupal/vendor/civicrm/civicrm-packages/HTML/QuickForm/Page.php(103): HTML_QuickForm_Controller-&gt;handle(Object(CRM_Contact_Form_Task_Email), 'upload')
  #17 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Core/Controller.php(355): HTML_QuickForm_Page-&gt;handle('upload')
  #18 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php(325): CRM_Core_Controller-&gt;run(Array, Array)
  #19 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php(69): CRM_Core_Invoke::runItem(Array)
  #20 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php(36): CRM_Core_Invoke::_invoke(Array)
  #21 /opt/drupal/web/modules/contrib/civicrm/src/Civicrm.php(88): CRM_Core_Invoke::invoke(Array)
  #22 /opt/drupal/web/modules/contrib/civicrm/src/Controller/CivicrmController.php(83): Drupal\civicrm\Civicrm-&gt;invoke(Array)
  #23 [internal function]: Drupal\civicrm\Controller\CivicrmController-&gt;main(Array, '')
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-05-01T08:18:13.977Z
Comments.Text: Quick email doesn't need cron.  Are there error messages in the log file?
Comments.UserDisplayName: Aidan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-05-01T10:40:03.233Z
Comments.Text: There is only this one liner in the log. Looks like the send call throws an exception:
  https://github.com/civicrm/civicrm-core/blob/a92aacaa76f5018dbe2dcd817a7b9ae0098c06dc/CRM/Utils/Mail.php#L211
Comments.UserDisplayName: Jan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-05-06T23:42:56.753Z
Comments.Text: You can try adding `$e->getTraceAsString()` to that line, so that it also logs the stack trace.
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-05-10T22:54:49.460Z
Comments.Text: I have added the stacktrace above. It doesn't tell me a lot though.
Comments.UserDisplayName: Jan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-05-11T00:30:24.540Z
Comments.Text: It tells us that `$message` is the problem var (3 lines up), so then my next step would be to debug what is `$message` and what is `$params['html']`, and if it's not obvious from that, then what happens inside `self::setEmailHeaders()`.
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-05-11T17:27:27.583Z
Comments.Text: Thanks for the hint. The issue is that I'm trying to send an empty body. No problem if I write something in the body. To whom can I address this?
Comments.UserDisplayName: Jan
Tags: <email>
Title: Mailing error: Expected a string or file resource
ThreadText: # Mailing error: Expected a string or file resource
  
  (Asked by: username_0 on 2024-04-30)
  
  I am getting the above error message when trying to send a quick email to less then 50 contacts via extended search. I setup the outgoing email as SMTP + sender address and was able to send a test email. I didn't configure any crons yet because I thought that was only required for CiviMail but maybe I'm wrong. Any help appreciated...
  Stacktrace top:
  [error] Mailing error: #0 /opt/drupal/vendor/pear/pear-core-minimal/src/PEAR.php(945): CRM_Core_Error::exceptionHandler(Object(PEAR_Error))
  #1 /opt/drupal/vendor/pear/pear-core-minimal/src/PEAR.php(577): PEAR_Error->__construct('Expected a stri...', NULL, 16, Array, NULL)
  #2 /opt/drupal/vendor/pear/pear-core-minimal/src/PEAR.php(236): PEAR::_raiseError(NULL, 'Expected a stri...')
  #3 /opt/drupal/vendor/pear/net_smtp/Net/SMTP.php(1220): PEAR::__callStatic('raiseError', Array)
  #4 /opt/drupal/vendor/pear/mail/Mail/smtp.php(391): Net_SMTP->data(NULL, 'MIME-Version: 1...')
  #5 /opt/drupal/vendor/pear/mail/Mail/smtp.php(319): Mail_smtp->send_or_fail(Array, Array, NULL)
  #6 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Utils/Mail/FilteredPearMailer.php(77): Mail_smtp->send(Array, Array, NULL)
  #7 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Utils/Mail.php(208): CRM_Utils_Mail_FilteredPearMailer->send(Array, Array, NULL)
  #8 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Contact/Form/Task/EmailTrait.php(934): CRM_Utils_Mail::send(Array)
  #9 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Contact/Form/Task/EmailTrait.php(797): CRM_Contact_Form_Task_Email->sendMessage('"CiviCRM" sendEmail('', '', '"CiviCRM" submit(Array)
  #12 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Core/Form.php(646): CRM_Contact_Form_Task_Email->postProcess()
  #13 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Core/QuickForm/Action/Upload.php(153): CRM_Core_Form->mainProcess()
  #14 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Core/QuickForm/Action/Upload.php(120): CRM_Core_QuickForm_Action_Upload->realPerform(Object(CRM_Contact_Form_Task_Email), 'upload')
  #15 /opt/drupal/vendor/civicrm/civicrm-packages/HTML/QuickForm/Controller.php(203): CRM_Core_QuickForm_Action_Upload->perform(Object(CRM_Contact_Form_Task_Email), 'upload')
  #16 /opt/drupal/vendor/civicrm/civicrm-packages/HTML/QuickForm/Page.php(103): HTML_QuickForm_Controller->handle(Object(CRM_Contact_Form_Task_Email), 'upload')
  #17 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Core/Controller.php(355): HTML_QuickForm_Page->handle('upload')
  #18 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php(325): CRM_Core_Controller->run(Array, Array)
  #19 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php(69): CRM_Core_Invoke::runItem(Array)
  #20 /opt/drupal/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php(36): CRM_Core_Invoke::_invoke(Array)
  #21 /opt/drupal/web/modules/contrib/civicrm/src/Civicrm.php(88): CRM_Core_Invoke::invoke(Array)
  #22 /opt/drupal/web/modules/contrib/civicrm/src/Controller/CivicrmController.php(83): Drupal\civicrm\Civicrm->invoke(Array)
  #23 [internal function]: Drupal\civicrm\Controller\CivicrmController->main(Array, '')
  
  **Tags:** email
  
  > **Comments:**
  > **username_1**: Quick email doesn't need cron.  Are there error messages in the log file?  
  > **username_0**: There is only this one liner in the log. Looks like the send call throws an exception: https://github.com/civicrm/civicrm-core/blob/a92aacaa76f5018dbe2dcd817a7b9ae0098c06dc/CRM/Utils/Mail.php#L211  
  > **username_2**: You can try adding `$e->getTraceAsString()` to that line, so that it also logs the stack trace.  
  > **username_0**: I have added the stacktrace above. It doesn't tell me a lot though.  
  > **username_2**: It tells us that `$message` is the problem var (3 lines up), so then my next step would be to debug what is `$message` and what is `$params['html']`, and if it's not obvious from that, then what happens inside `self::setEmailHeaders()`.  
  > **username_0**: Thanks for the hint. The issue is that I'm trying to send an empty body. No problem if I write something in the body. To whom can I address this?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2024-05-12. Score: 1 | Accepted answer
  
  I've put up a PR at <https://github.com/civicrm/civicrm-core/pull/30172>. It worked for me. Can you confirm it also fixes it for you?
  
  Just on line 208 of CRM/Utils/Mail.php, change
  
  `$result = $mailer->send($to, $headers, $message);`
  
  to
  
  `$result = $mailer->send($to, $headers, $message ?? '');`
  
  > **Comments:**
  > **username_0**: Yes, it's fixed. I wouldn't do the null check inside the send call though, probably inside setEmailHeaders.  
  
  ---
  
  