I use the smtp module in conjunction with the yamlform module and have in this form a field for file upload. But in the e-mail message I have this field not included.

After submit the form I get the error from SMTPMailSystem:

Warning: Invalid argument supplied for foreach() in Drupal\smtp\Plugin\Mail\SMTPMailSystem->mail() (line 404 of modules/contrib/smtp/src/Plugin/Mail/SMTPMailSystem.php).

Drupal\smtp\Plugin\Mail\SMTPMailSystem->mail(Array) (Line: 227)
Drupal\Core\Mail\MailManager->mail('yamlform', 'email.e_mail', 'xxxxx', 'de', Array, 'xxxxx') (Line: 509)
Drupal\yamlform\Plugin\YamlFormHandler\EmailYamlFormHandler->sendMessage(Array) (Line: 418)
Drupal\yamlform\Plugin\YamlFormHandler\EmailYamlFormHandler->postSave(Object, , NULL) (Line: 1248)
Drupal\yamlform\Entity\YamlForm->invokeHandlers('postSave', Object, , NULL) (Line: 557)
Drupal\yamlform\YamlFormSubmissionStorage->invokeYamlFormHandlers('postSave', Object, ) (Line: 524)
Drupal\yamlform\YamlFormSubmissionStorage->doPostSave(Object, ) (Line: 395)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 761)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 364)
Drupal\Core\Entity\Entity->save() (Line: 603)
Drupal\yamlform\Entity\YamlFormSubmission->save() (Line: 747)
Drupal\yamlform\YamlFormSubmissionForm->save(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 583)
Drupal\Core\Form\FormBuilder->processForm('yamlform_submission_application_form_form', Array, Object) (Line: 314)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 48)
Drupal\Core\Entity\EntityFormBuilder->getForm(Object) (Line: 601)
Drupal\yamlform\Entity\YamlForm->getSubmissionForm(Array) (Line: 83)
Drupal\yamlform\Controller\YamlFormTestController->testForm(Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array) (Line: 144)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 98)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 77)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 628)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

The problem is that in my case the "$message['params']['attachments']" variable is not empty, instead it contains "false". So the if condition in line 404 is satisfied.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cbeier created an issue. See original summary.

cbeier’s picture

simgui8’s picture

Same as cbeier,

warning when submitting a yamlform.
same reason.

This patch fix it lattest dev 2016-oct-17

cbeier’s picture

cbeier’s picture

Status: Active » Needs review
cbeier’s picture

estoyausente’s picture

Status: Needs review » Reviewed & tested by the community

It seems ok. It is a simple patch.

Chris Matthews’s picture

The patch in #6 was RTBC'd 3 years ago and still applies cleanly to 8.x-1.x-dev. Can this be committed?

git apply -v smtp-empty-attachment-2783207-6.patch
Checking patch src/Plugin/Mail/SMTPMailSystem.php...
Hunk #1 succeeded at 491 (offset 47 lines).
Applied patch src/Plugin/Mail/SMTPMailSystem.php cleanly.
wundo’s picture

Version: 8.x-1.x-dev » 8.x-1.0-beta5

  • wundo committed 1efecd9 on 8.x-1.x authored by cbeier
    Issue #2783207 by cbeier, simgui8, estoyausente, Chris Matthews: "...
wundo’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.