verbb / formie

The most user-friendly forms plugin for Craft CMS.
Other
93 stars 68 forks source link

Formie does not send notification emails #1892

Closed hheckel closed 3 weeks ago

hheckel commented 1 month ago

Describe the bug

Updated my system to Craft 5. Had to re-install Formie (PHP bug), now I won't be able to send notification emails: Failed to send notification email: {"error":"Fehler beim Parsen der E-Mail-Benachrichtigung für “An: {field:ihreEmailAdresse}”. Vorlagenfehler: “The directory does not exist: ” \/var\/www\/html\/vendor\/yiisoft\/yii2\/web\/AssetManager.php:238"}. I tried without and with email templates, no changes. I created a form from scratch, no changes.

Formie will send emails from the backend using the "resend" function, but not when triggered through a form from the frontend.

Using SendGrid to send emails.

Steps to reproduce

  1. Set up a form with notification email
  2. Fill out form - no email is sent

Form settings

Craft CMS version

5.1.3

Plugin version

3.0.0-beta.10

Multi-site?

No

Additional context

No response

engram-design commented 1 month ago

Was the PHP bug that meant you needed to reinstall Formie related to Formie? Let me know!

If the email is sending when using the "resend" function, but not through normal front-end processes, then that tells me there's something wrong with sending out the email via the queue.

Can you send through the full stack trace of the error? Just trying to figure out where in the process of using a variable like the ihreEmailAdresse field it's trying to access anything about assets (the AssetManager line) as that seems odd.

hheckel commented 1 month ago

Was the PHP bug that meant you needed to reinstall Formie related to Formie? Let me know! I don't know for sure. Actually, you gave me the hint to re-install Formie: #1864

image

Does that help?

engram-design commented 1 month ago

Ah gotcha. Are you able to send through your logs to support@verbb.io? These are found in /storage/logs. This should include the trace back through the classes for where this is being called from. First occurrence I've seen of this!

hheckel commented 1 month ago

This might help more...

2024-05-21 15:12:58 [queue.ERROR] [verbb\formie\jobs\BaseJob::updatePayload] Aktualisierung der Job-Info-Debugging nicht möglich: "Serialization of 'Closure' is not allowed" /var/www/html/vendor/yiisoft/yii2-queue/src/serializers/PhpSerializer.php:24 {"memory":24684984} 2024-05-21 15:12:58 [queue.ERROR] [Exception] Exception: Failed to send notification email: {"error":"Fehler beim Parsen der E-Mail-Benachrichtigung für “An: {field:ihreAngaben.ihreEmailAdresse}”. Vorlagenfehler: “The directory does not exist: ” \/var\/www\/html\/vendor\/yiisoft\/yii2\/web\/AssetManager.php:238"}. in /var/www/html/vendor/verbb/formie/src/jobs/SendNotification.php:74 Stack trace:

0 /var/www/html/vendor/yiisoft/yii2-queue/src/Queue.php(243): verbb\formie\jobs\SendNotification->execute(Object(craft\queue\Queue))

1 /var/www/html/vendor/yiisoft/yii2-queue/src/cli/Queue.php(162): yii\queue\Queue->handleMessage('591', 'O:34:"verbb\for...', '300', '1')

2 /var/www/html/vendor/yiisoft/yii2-queue/src/cli/Command.php(146): yii\queue\cli\Queue->execute('591', 'O:34:"verbb\for...', '300', '1', '69015')

3 [internal function]: yii\queue\cli\Command->actionExec('591', '300', '1', '69015')

4 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)

5 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)

6 /var/www/html/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('exec', Array)

7 /var/www/html/vendor/craftcms/cms/src/console/ControllerTrait.php(89): yii\console\Controller->runAction('exec', Array)

8 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): craft\queue\Command->runAction('exec', Array)

9 /var/www/html/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('queue/exec', Array)

10 /var/www/html/vendor/craftcms/cms/src/console/Application.php(91): yii\console\Application->runAction('queue/exec', Array)

11 /var/www/html/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('queue/exec', Array)

12 /var/www/html/vendor/craftcms/cms/src/console/Application.php(122): yii\console\Application->handleRequest(Object(craft\console\Request))

13 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest(Object(craft\console\Request))

14 /var/www/html/craft(13): yii\base\Application->run()

15 {main} {"memory":24672280,"exception":"[object] (Exception(code: 0): Failed to send notification email: {\"error\":\"Fehler beim Parsen der E-Mail-Benachrichtigung für “An: {field:ihreAngaben.ihreEmailAdresse}”. Vorlagenfehler: “The directory does not exist: ” \/var\/www\/html\/vendor\/yiisoft\/yii2\/web\/AssetManager.php:238\"}. at /var/www/html/vendor/verbb/formie/src/jobs/SendNotification.php:74)"}

engram-design commented 1 month ago

Looking up AssetManager.php:238 makes me think that something is wrong with file permissions somewhere down the line. Is this something you can check on your install and environment?

hheckel commented 1 month ago

This happens with or without any email template – so what kind of permission issue could it be? any hints?

hheckel commented 1 month ago

It seems that Formie does not extract the data from the submission into the notification. In Job Data as well as when looking into the send notification, almost everything is empty, especially the email address. Also, I was not clear – "resend" did not work, but opening the submission and sending the notification from there works.

So it seems to me that the notification sending tries to start before the submission is saved properly... Does that make sense?

hheckel commented 1 month ago

When I look at the Sent Notifications, the unsuccessful ones are empty (no preview of the email), the ones that were sent are complete with email preview. Also, it makes no difference if the submission reloads the page or does an AJAX refresh, if Cloudflare Spam is enabled or not, if a template is used or not.

engram-design commented 1 month ago

By permissions, I meant file permissions. Something is trying to write something to the file system but cannot.

The job data being empty is pretty normal. It's supposed to get updated after an error happens, but it doesn't always. This is because the data for the submission can be dynamic, and isn't set at the time of submission. It's purely a visual/debug thing though, everything in the queue job deals with a proper populated submission, this is just visual feedback.

The difference between a normal submission is that emails are sent via the queue. When you hit "resend" they aren't using the queue, so it seems related to the queue. How does your queue processing run? Do you leave it as the default (only run when someone visits the control panel), a corn job, or a daemon?

hheckel commented 3 weeks ago

I am using AsyncQueue to run jobs immediately after they have been added to the queue, since I do not have admin panel access on my production site.

The AsyncQueue Test runs smoothly, just the Formie notifications won't be sent.

Just to clarify this again - "resend" from a failed queue job does NOT go through. Going into Formie - Submissions - [submission] - resend email notification (see screenshot) works though.

image
hheckel commented 3 weeks ago

Also, I doubt that there is a file permission issue, since exactly the same error appears on my local dev and our hosted stage environment. Since we are hosted through servd and everything used to work fine prior to upgrading to Craft 5 (and Formie 3) and everything else is running smoothly, this really looks strange to me.

Complete re-install, other template directory, disabling AsyncQueue - did not work.

engram-design commented 3 weeks ago

I have seen issues with the AsyncQueue plugin in the past, so it may be related to that - but as your last update mentioned you've tested that. It might also be related to Servd. I'll get a test site spun up just in case.

It does seem odd that you're experiencing it locally though, and I certainly can't replicate it. Wondering if you might be up for sending your composer.json and composer.lock files along with a database export to support@verbb.io? It sounds like it might be unique to your setup. Totally understand if you're unable to share.

hheckel commented 3 weeks ago

I have a different error log now...:

2024-06-03 11:00:22 [INFO] Submission triggered for simple.
2024-06-03 11:00:22 [INFO] Request context:
$_GET = []

$_POST = [
    'CRAFT_CSRF_TOKEN' => '••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••'
    'action' => 'formie/submissions/submit'
    'submitAction' => 'submit'
    'handle' => 'simple'
    'siteId' => '1'
    'fields' => [
        'email' => 'someone@email.com'
    ]
]
2024-06-03 11:00:23 [ERROR] Fehler beim Parsen der E-Mail-Benachrichtigungsvorlage für "_formie/extern.twig". Vorlagenfehler: "The directory does not exist: " /var/www/html/vendor/yiisoft/yii2/web/AssetManager.php:238
2024-06-03 11:00:23 [ERROR] yii\base\InvalidConfigException: The directory does not exist:  in /var/www/html/vendor/yiisoft/yii2/web/AssetManager.php:238
Stack trace:
#0 /var/www/html/vendor/yiisoft/yii2/web/AssetManager.php(555): yii\web\AssetManager->checkBasePathPermission()
#1 /var/www/html/vendor/yiisoft/yii2/web/AssetManager.php(487): yii\web\AssetManager->publishDirectory('/var/www/html/v...', Array)
#2 /var/www/html/vendor/yiisoft/yii2/web/AssetBundle.php(181): yii\web\AssetManager->publish('/var/www/html/v...', Array)
#3 /var/www/html/vendor/yiisoft/yii2/web/AssetManager.php(294): yii\web\AssetBundle->publish(Object(yii\web\AssetManager))
#4 /var/www/html/vendor/yiisoft/yii2/web/AssetManager.php(265): yii\web\AssetManager->loadBundle('swdevelopment\\a...', Array, true)
#5 /var/www/html/vendor/yiisoft/yii2/web/View.php(296): yii\web\AssetManager->getBundle('swdevelopment\\a...')
#6 /var/www/html/vendor/craftcms/cms/src/web/View.php(2106): yii\web\View->registerAssetBundle('swdevelopment\\a...', NULL)
#7 /var/www/html/vendor/swdevelopment/animate/src/Animate.php(175): craft\web\View->registerAssetBundle('swdevelopment\\a...')
#8 /var/www/html/vendor/swdevelopment/animate/src/Animate.php(122): swdevelopment\animate\Animate->loadAnimate()
#9 [internal function]: swdevelopment\animate\Animate->swdevelopment\animate\{closure}(Object(craft\events\TemplateEvent))
#10 /var/www/html/vendor/yiisoft/yii2/base/Event.php(312): call_user_func(Object(Closure), Object(craft\events\TemplateEvent))
#11 /var/www/html/vendor/yiisoft/yii2/base/Component.php(642): yii\base\Event::trigger('craft\\web\\View', 'beforeRenderTem...', Object(craft\events\TemplateEvent))
#12 /var/www/html/vendor/craftcms/cms/src/web/View.php(1909): yii\base\Component->trigger('beforeRenderTem...', Object(craft\events\TemplateEvent))
#13 /var/www/html/vendor/craftcms/cms/src/web/View.php(468): craft\web\View->beforeRenderTemplate('formie/_special...', Array, 'cp')
#14 /var/www/html/vendor/verbb/formie/src/models/Notification.php(166): craft\web\View->renderTemplate('formie/_special...', Array, 'cp')
#15 /var/www/html/vendor/verbb/formie/src/base/Field.php(1261): verbb\formie\models\Notification->renderTemplate(Array, Array)
#16 /var/www/html/vendor/verbb/formie/src/helpers/Variables.php(302): verbb\formie\base\Field->getEmailHtml(Object(verbb\formie\elements\Submission), Object(verbb\formie\models\Notification), 'hannes.muc@me.c...')
#17 /var/www/html/vendor/verbb/formie/src/helpers/Variables.php(238): verbb\formie\helpers\Variables::getFieldsHtml(Object(verbb\formie\elements\Form), Object(verbb\formie\models\Notification), Object(verbb\formie\elements\Submission))
#18 /var/www/html/vendor/verbb/formie/src/services/Emails.php(250): verbb\formie\helpers\Variables::getParsedValue('<p>{allFields}<...', Object(verbb\formie\elements\Submission), Object(verbb\formie\elements\Form), Object(verbb\formie\models\Notification), true)
#19 /var/www/html/vendor/verbb/formie/src/services/Emails.php(320): verbb\formie\services\Emails->renderEmail(Object(verbb\formie\models\Notification), Object(verbb\formie\elements\Submission))
#20 /var/www/html/vendor/verbb/formie/src/services/Submissions.php(212): verbb\formie\services\Emails->sendEmail(Object(verbb\formie\models\Notification), Object(verbb\formie\elements\Submission), Object(verbb\formie\jobs\SendNotification))
#21 /var/www/html/vendor/verbb/formie/src/jobs/SendNotification.php(66): verbb\formie\services\Submissions->sendNotificationEmail(Object(verbb\formie\models\Notification), Object(verbb\formie\elements\Submission), Object(verbb\formie\jobs\SendNotification))
#22 /var/www/html/vendor/yiisoft/yii2-queue/src/Queue.php(243): verbb\formie\jobs\SendNotification->execute(Object(craft\queue\Queue))
#23 /var/www/html/vendor/yiisoft/yii2-queue/src/cli/Queue.php(162): yii\queue\Queue->handleMessage('651', 'O:34:"verbb\\for...', '300', '1')
#24 /var/www/html/vendor/yiisoft/yii2-queue/src/cli/Command.php(146): yii\queue\cli\Queue->execute('651', 'O:34:"verbb\\for...', '300', '1', '2769')
#25 [internal function]: yii\queue\cli\Command->actionExec('651', '300', '1', '2769')
#26 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#27 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#28 /var/www/html/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('exec', Array)
#29 /var/www/html/vendor/craftcms/cms/src/console/ControllerTrait.php(89): yii\console\Controller->runAction('exec', Array)
#30 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): craft\queue\Command->runAction('exec', Array)
#31 /var/www/html/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('queue/exec', Array)
#32 /var/www/html/vendor/craftcms/cms/src/console/Application.php(91): yii\console\Application->runAction('queue/exec', Array)
#33 /var/www/html/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('queue/exec', Array)
#34 /var/www/html/vendor/craftcms/cms/src/console/Application.php(122): yii\console\Application->handleRequest(Object(craft\console\Request))
#35 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest(Object(craft\console\Request))
#36 /var/www/html/craft(13): yii\base\Application->run()
#37 {main}

The asset mngr seems to be looking for a directory path that simply isn't there...? Note the space after the colon:

"The directory does not exist: "

hheckel commented 3 weeks ago

I have seen issues with the AsyncQueue plugin in the past, so it may be related to that - but as your last update mentioned you've tested that. It might also be related to Servd. I'll get a test site spun up just in case.

It does seem odd that you're experiencing it locally though, and I certainly can't replicate it. Wondering if you might be up for sending your composer.json and composer.lock files along with a database export to support@verbb.io? It sounds like it might be unique to your setup. Totally understand if you're unable to share.

I can send the composer files, I can't send the DB – or maybe tell me which DB table you want to look at (hundreds of GB).

engram-design commented 3 weeks ago

So that seems to be coming from this plugin?

#7 /var/www/html/vendor/swdevelopment/animate/src/Animate.php(175): craft\web\View->registerAssetBundle('swdevelopment\\a...')
#8 /var/www/html/vendor/swdevelopment/animate/src/Animate.php(122): swdevelopment\animate\Animate->loadAnimate()
#9 [internal function]: swdevelopment\animate\Animate->swdevelopment\animate\{closure}(Object(craft\events\TemplateEvent))
hheckel commented 3 weeks ago

OMG. Yes, disabling the animate plugin totally solved this issue. Thank you for your forensics.