Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

Address in mailbox given does not comply with RFC 2822, 3.6.2. #382

Closed
fabienlege opened this issue Oct 1, 2013 · 35 comments
Closed

Address in mailbox given does not comply with RFC 2822, 3.6.2. #382

fabienlege opened this issue Oct 1, 2013 · 35 comments

Comments

@fabienlege
Copy link

When i try to send a newsletter i have this error :
Address in mailbox given [agence-immobiliere-aaaaaaaa@wanadoo.fr
] does not comply with RFC 2822, 3.6.2.

I don't understand what is wrong because this address realy exist...

@prafful-panwar
Copy link

The exception itself says there is something wrong in email address fields such as From, Sender or Reply-To fields. Swift Mailer strictly follow RFC standard to avoid emails being caught by spam checker tools. There are following reason can lead to this error.

Incorrect email address format in to,from or reply-to fields
Email address or host does not exist
From email address should be valid working email address
Not fully qualified domain name used in from email address
To fix this error check above settings in you script and fix accordingly. You may need to check RFC standard to fix this error. If still does not fix error you can disable email address RFC standard checking code in swift mailer script. Obviously this is not recommended but some time developer need to apply fix temporarily.

Before applying please check Swift Mailer documentation on how to set To,From,Cc, Bcc, Reply To fields correctly in Swift Mailer.

How To Disable RFC Standard Check

Go to swiftmailer\classes\Swift\Mime\Headers folder and open MailboxHeader.php file in editor. Go to line number 304 and comment throw exception line as specified below.

For Symfony users: swift mailer library can be found in vendor folder.

private function _assertValidAddress($address)
{
if (!preg_match('/^' . $this->getGrammar('addr-spec') . '$/D',
$address))
{
//throw new Swift_RfcComplianceException(
// 'Address in mailbox given [' . $address .
// '] does not comply with RFC 2822, 3.6.2.'
// );
}
}
The error should be disappear now.

@SashaDesigN
Copy link

its didnt help me
this error stop all my code

@SashaDesigN
Copy link

Its help me - before send message I do mysql_real_escape_string()

@truckee
Copy link

truckee commented Feb 24, 2015

Comment deleted due to factual error. Apologies.

@LouTerrailloune
Copy link

For googlers, I had the same issue. The problem was the PCRE lib version used by the mod_php which dont want to compile the regex used by swiftmailer to check addresses. (there is a warning the the php logs).

@p3ngu1n-net
Copy link

Lou: which one did you use? Thanks!

@LouTerrailloune
Copy link

@bastianmartin I did not change the pcre lib because I dont have the right on the server. I just made an ugly fork and removed the check. See LouTerrailloune/swiftmailer@d71ecbb .

@p3ngu1n-net
Copy link

@LouTerrailloune Thank you! I'm trying to update PHP libs - maybe it was already fixed. Otherwise I'm gonna comment that too... damn ;-)

@LouTerrailloune
Copy link

I still have some warnings in the logs, be carefull.
See #259
An interesting post: http://stackoverflow.com/questions/15963755/swift-rfccomplianceexception-on-valid-email-address-works-in-windows-not-in-ubu

@p3ngu1n-net
Copy link

Thanks - I've updated PHP to the latest DotDeb Build (5.6.10) and the issue is gone.

@Pierstoval
Copy link

Why not change this code:

if (!preg_match('/^' . $this->getGrammar()->getDefinition('addr-spec') . '$/D', $address))

With this:

if (0 === preg_match('/^' . $this->getGrammar()->getDefinition('addr-spec') . '$/D', $address))

Then, any false will throw a classical error that will not break up the entire application.
Could also add a @ right before preg_match to be sure no error is thrown.

@rameezrami
Copy link

plz make sure there is no white space before or after the email address given

@Pierstoval
Copy link

It's your role to use trim on the email address before sending it to Swiftmailer, I think

@p3ngu1n-net
Copy link

In my case, PHP was the culprit. After updating to 5.6.10 (without changing the existing PHP code) the issue was gone. However, I also think that Swiftmailer should use trim on the addresses.

@obense
Copy link

obense commented Sep 1, 2015

In my case, it works after updating PHP from 5.5.25 to 5.5.28.

ramainen added a commit to ramainen/doit-cms that referenced this issue Nov 20, 2015
@wyklif
Copy link

wyklif commented May 14, 2016

in my case it was a blank bcc

@sa3dwi
Copy link

sa3dwi commented Oct 3, 2016

i used iconv() and trim() to fix this issue

@SashaDesigN
Copy link

trim() helps me too ^^)

@ventoh
Copy link

ventoh commented Nov 10, 2016

same error here. Trim not helped me. This are the emails that throw the error:

lian.schmitt@example.com
nathanaël.riviere@example.com

Really i don't want to send those emails, it's just a simulation, but this error break it.
any hint?

@MikeOtown
Copy link

Mandrill gives me an SMTP username that is not valid email address and SwiftMailer is throwing an error.

@kir86975
Copy link

Hello! I can't to send any e-mail with addresses пример@пример.рф or example@пример.рф and get the same error. Google supports this addresses. Why are you not support it?

@naffiq
Copy link

naffiq commented Aug 11, 2017

Hello!

Seems like an old issue, but I don't know where to post this.

I'm using mailgun.com service, and there is a feature of batch sending emails, by defining receiver as %recipient% and adding header, containing recipients data.

It would be great, if there would be a way to redefine Swift_Mime_Grammar as DI and create interface for it?

@fabpot
Copy link
Member

fabpot commented Aug 11, 2017

Closing as the email validation is now done by an external library that you can configure (Swiftmailer 6+).

@fabpot fabpot closed this as completed Aug 11, 2017
@gondo
Copy link
Contributor

gondo commented Jun 7, 2018

@fabpot how can you configure this external library? link to documentation or an example would be extremely helpful
see #999

@ozhala
Copy link

ozhala commented Jul 25, 2018

Work for me just fine
$trim_ = trim($email);
$filter_var = filter_var($trim, FILTER_SANITIZE_EMAIL);
$iconv = iconv('ISO-8859-1','UTF-8//IGNORE', $filter_var);

@stasionok
Copy link

Hello! I can't to send any e-mail with addresses пример@пример.рф or example@пример.рф and get the same error. Google supports this addresses. Why are you not support it?

You should convert your пример.рф domain into IDNA format like 'xn--e1afmkfd.xn--p1ai'

@safiullahsarhandi
Copy link

i was also getting this problem when i was sending multiple emails at a time and there was email duplication passed in bcc , to , CC methods

$message->to('abc@gmail.com')->bcc(['abc@gmail.com','johndoe@gmail.com']);

@Acksop
Copy link

Acksop commented Mar 12, 2020

Simply change 👍

$email = new Swift_Message();
    $email->setSender(array('xxxxxxx@xxxxxxx.xxx' => "Le ROBOT-gueulard(t) du (B25)"));

and
swiftmailer-5.x/lib/classes/Swift/Message.php at line 46 by
array($this, 'Swift_Message::__construct'),
instead of
array($this, 'Swift_Mime_SimpleMessage::__construct'),

@abardik
Copy link

abardik commented Apr 10, 2020

For me, it was empty email address sent to setReplyTo(). Fixed by not calling this method if reply-to is absent. I think, the same would be with setFrom, setCc, setBcc.

@ttuchtfeldt
Copy link

In my case it was a blank bcc, too!

@drudriger
Copy link

In my case was empty "To Name"
it was
$message->setTo(['my@email.to'])
and need be
$message->setTo(['my@email.to' => 'my name'])

@fabpot
Copy link
Member

fabpot commented Jun 25, 2020

@drudriger Good finding. Would you like to work on a fix? I suppose that the conversion to an email address is wrong when the name is empty.

@drudriger
Copy link

drudriger commented Jun 25, 2020

I spend around 2 hours, find the problem. But me problem was not that name was empty, but because I give to the method like this
$message->setTo(['my@email.to' , 'my name'])
So swiftMail think that the my name is email address. May help to somebody to know..
When I have a time I have look, what happen, if name if really empty and if give you an error. If is it, I try to fix it.
new: yes if a name is empty give you an error. I have look to the code. to fix it, If I find way how, I make a PR for it.

@i-internet
Copy link

in my case it was a blank bcc
Your comment should be on top somewhere

@clarcked
Copy link

clarcked commented Apr 5, 2021

This looks like a very old question. Recently, I've got an error like this because i have put the email address in the name argument and vice versa. Maybe this comment can help someone...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests