getgrav / grav-plugin-email

Grav Email Plugin
http://getgrav.org
MIT License
37 stars 29 forks source link

Address in mailbox given [] does not comply with RFC 2822 #139

Closed 01Kuzma closed 2 years ago

01Kuzma commented 4 years ago

I'm using latest Grav 1.7 RC17 version. Developing a new project locally. I've set email plugin with external SMTP server and it does send mails.

The problem is with a contact form. I've made a validation and Ajax submission. The email field is not mandatory and here comes this error: Address in mailbox given [] does not comply with RFC 2822 If I fill the email input - no error. I've seen that a few people had this problem long before and no fix was provided. In some similar mailing projects the solution is pretty simple - use additional trim functions in php code to allow empty email if it's not required.

Here is my form:

form:
  name: kontakt-ajax-form
  template: form-messages
  refresh_prevention: true
  fields:
    -
      name: email
      label: false
      placeholder: 'e mail'
      type: email
      outerclasses: form-field
      classes: full-width
    -
      name: brand
      autofocus: 'off'
      autocomplete: 'on'
      type: select
      options:
        ...
            many option
        ...
      validate:
        required: true
    -
      name: telephone
      label: Phone
      placeholder: Phone
      type: tel
      validate:
        required: true
    -
      name: message
      label: false
      type: textarea
      outerclasses: form-field
      classes: full-width
      rows: null
  buttons:
    -
      type: submit
      value: Submit
      outerclasses: form-field
      classes: 'full-width btn--primary'
  process:
    -
      email:
        from: '{{ config.plugins.email.from }}'
        to: ['{{ config.plugins.email.to }}', '{{ form.value.email }}']
        subject: '[Message from] {{ form.value.name|e }}'
        body: '{% include ''forms/data.html.twig'' %}'
    -
      message: 'Thank you message'

And jQuery validation from jqueryvalidation.org:

$(function() {
            $('#kontakt-ajax-form').validate({

                errorPlacement: function(error, element) {      

                rules: {
                    'data[brand]': 'required',
                    'data[phone]': 'required',
                    'data[email]': {
                        required: false,
                        email: true
                    },

                },

                messages: {
                            xxx
                },

                submitHandler: function (form, event) {

                    event.preventDefault();                     

                    var submitBtn = $('.button');
                    submitBtn.attr('disabled', 'disabled');

                    var form = $('.contact__main form');

                    $.ajax({
                        url: form.attr('action'),
                        type: form.attr('method'),
                            dataType: 'html',
                            data: $(form).serialize(),                      

                            success: function (result) {
                                submitBtn.removeAttr('disabled');
                                submitBtn.html('Siųsti');
                                $('.message-success').show();
                                $('.message-success').html(result);

                            },
                              error: function(e) {

                                console.log(e);
                              }
                    });                                     

                    return false;                
                }
            });

        });

The full error from console.log: "{\"error\":{\"type\":\"Swift_RfcComplianceException\",\"message\":\"Address in mailbox given [] does not comply with RFC 2822, 3.6.2.\",\"file\":\"C:\\\\xampp\\\\htdocs\\\\project\\\\user\\\\plugins\\\\email\\\\vendor\\\\swiftmailer\\\\swiftmailer\\\\lib\\\\classes\\\\Swift\\\\Mime\\\\Headers\\\\MailboxHeader.php\",\"line\":355}}"

rhukster commented 2 years ago

Please test with Email 4.0 as it's been rewritten with Symfony/Mailer and more flexible email address formats. (https://getgrav.org/blog/new-email-plugin)