Problem/Motivation
When not logged in, it seems that trying to send a contact form automatically adds the anonymous user empty email address to the "addresses" array of the email object (in reply-to I think).
Steps to reproduce:
- Create a contact form.
- Go to "Manage form display" and set "Sender email" to disabled
- Log out, and visit the contact form as anonymous
- Send the message and see an error "Unable to send email. Contact the site administrator if the problem persists."
- A log message is generated "Error sending email: Email "" does not comply with addr-spec of RFC 2822."
Proposed resolution
Prevent getSymfonyEmail() from adding empty addresses ?
It should be fixed at the source - i.e. in this case, in the contact form module, but it could be worth not breaking the sending of any email with multiple addresses due to one empty email.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | screenshot-contact-form-fields-symfony-mailer.png | 27.38 KB | paulmicha |
| #2 | symfony_mailer-errorSendingEmailDoesNotComplyRFC-3401849-1.patch | 559 bytes | paulmicha |
Issue fork symfony_mailer-3401849
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
paulmicha commentedCurrent workaround : cf. patch attached.
Comment #3
adamps commentedI can't reproduce this. When sending as anonymous then there is a box to put your email address in. Perhaps you have disabled the field on your site?
Comment #4
paulmicha commentedIndeed, could it be that the switch from Swiftmailer to Symfony Mailer has introduced these fields ?
In our case, it seems preferable not to add those fields to the existing forms.
Comment #5
adamps commentedNo, the field I refer to is part of Core.
Interesting I'm surprised that it worked without using this module. I had imagined that this field is mandatory.
I believe that the right fix is in ContactEmailBuilderBase
Comment #6
mrcdrx commentedI can confirm that the patch in #2 works.
Comment #7
adamps commentedComment #8
adamps commentedSee #5 for the proposed 1-line fix
Comment #9
koustav_mondal commentedWorking on it.
Comment #11
koustav_mondal commented@adamps I made the changes according to #5 . Please have a look.
Comment #12
adamps commentedThanks. There is a merge conflict unfortunately.
Comment #16
brandonlira commentedComment #18
brandonlira commentedHi everyone,
I have updated the fix to target the correct version (1.4.0) by creating a new branch based on 1.x. The previous merge request was for 2.x, but after reviewing the issue and its comments, I realized that the correct fix should be applied to 1.4.0.
I have now submitted a new Merge Request (!143) for this version. Please review the changes and let me know if anything needs to be adjusted.
Additionally, I noticed that some PHPStan checks have failed. From my understanding, these errors seem to be pre-existing and unrelated to this MR. Could someone confirm if I should address them, or if they can be handled separately?
Thanks!
Comment #19
brandonlira commentedComment #20
adamps commentedAll fixes now go in 2.x please. The file is now ContactMailer.php and the code to change is line 100
Comment #21
brandonlira commentedComment #24
brandonlira commentedHi @adamps,
I have moved the fix to ContactMailer.php (line 100) for 2.x MR (!144) and added a check to ensure $sender is not NULL before calling setReplyTo().
Please review and let me know if any adjustments are needed.
Thanks!
Comment #25
brandonlira commentedComment #26
adamps commentedThanks it looks good.
This needs someone to do a manual test. I added "steps to reproduce" in the issue summary. First run them without this patch and check you see the error. Then apply the patch and confirm the problem is fixed.
Comment #27
adamps commentedComment #29
adamps commentedGood job I tested it as it didn't work. In future please test fixes if you want to get credit😃.