New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
fabienlege opened this Issue Oct 1, 2013 · 25 comments

Comments

Projects
None yet
@fabienlege

fabienlege commented Oct 1, 2013

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

This comment has been minimized.

prafful-panwar commented Oct 1, 2013

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

This comment has been minimized.

SashaDesigN commented Feb 4, 2015

its didnt help me
this error stop all my code

@SashaDesigN

This comment has been minimized.

SashaDesigN commented Feb 4, 2015

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

@truckee

This comment has been minimized.

truckee commented Feb 24, 2015

Comment deleted due to factual error. Apologies.

@LouTerrailloune

This comment has been minimized.

LouTerrailloune commented Jun 16, 2015

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).

@bastianmartin

This comment has been minimized.

bastianmartin commented Jun 16, 2015

Lou: which one did you use? Thanks!

@LouTerrailloune

This comment has been minimized.

LouTerrailloune commented Jun 16, 2015

@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 .

@bastianmartin

This comment has been minimized.

bastianmartin commented Jun 16, 2015

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

@LouTerrailloune

This comment has been minimized.

LouTerrailloune commented Jun 16, 2015

@bastianmartin

This comment has been minimized.

bastianmartin commented Jun 16, 2015

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

@Pierstoval

This comment has been minimized.

Pierstoval commented Jun 16, 2015

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

This comment has been minimized.

rameezrami commented Jul 24, 2015

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

@Pierstoval

This comment has been minimized.

Pierstoval commented Jul 25, 2015

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

@bastianmartin

This comment has been minimized.

bastianmartin commented Jul 25, 2015

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

This comment has been minimized.

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

This comment has been minimized.

wyklif commented May 14, 2016

in my case it was a blank bcc

@sa3dwi

This comment has been minimized.

sa3dwi commented Oct 3, 2016

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

@SashaDesigN

This comment has been minimized.

SashaDesigN commented Oct 10, 2016

trim() helps me too ^^)

@ventoh

This comment has been minimized.

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

This comment has been minimized.

MikeOtown commented Apr 11, 2017

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

@kir86975

This comment has been minimized.

kir86975 commented Apr 12, 2017

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

This comment has been minimized.

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

This comment has been minimized.

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 Aug 11, 2017

@gondo

This comment has been minimized.

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

This comment has been minimized.

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment