I have a correct email address. I have echoed it, but when I send it, I get the following error:
Address in mailbox given [] does not comply with RFC 2822, 3.6.2.
Why? I use laravel (swift mailer) to send email:
$email = [email protected]
and then when I send it, the error is thrown.
But if I directly use the string, it sends it.
Here is the block:
Mail::send('emails.activation', $data, function($message){
$message->to($email)->subject($subject);
});
->with('title', "Registered Successfully.");
This question is related to
php
email
laravel
laravel-4
swiftmailer
I have faced the same problem and I have fixed. Please make sure some things as written bellow :
Mail::send('emails.auth.activate', array('link'=> URL::route('account-activate', $code),'username'=>$user->username),function($message) use ($user) {
$message->to($user->email , $user->username)->subject('Active your account !');
});
This should be your emails.activation
Hello {{ $username }} , <br> <br> <br>
We have created your account ! Awesome ! Please activate by clicking the following link <br> <br> <br>
----- <br>
{{ $link }} <br> <br> <br>
----
The answer to your why you can't call $email variable into your mail sending function. You need to call $user variable then you can write your desired variable as $user->variable
Thank You :)
[SOLVED] Neos/swiftmailer: Address in mailbox given [] does not comply with RFC 2822, 3.6.2
Exception in line 261 of /var/www/html/vendor/Packages/Libraries/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php: Address in mailbox given [] does not comply with RFC 2822, 3.6.2.
private function _assertValidAddress($address)
{
if (!preg_match('/^'.$this->getGrammar()->getDefinition('addr-spec').'$/D',
$address)) {
throw new Swift_RfcComplianceException(
'Address in mailbox given ['.$address.
'] does not comply with RFC 2822, 3.6.2.'
);
}
}
Your email variable is empty because of the scope, you should set a use clause such as:
Mail::send('emails.activation', $data, function($message) use ($email, $subject) {
$message->to($email)->subject($subject);
});
I had very similar problem today and solution was as it is..
$email = Array("Zaffar Saffee" => "[email protected]");
$schedule->command('cmd:mycmd')
->everyMinute()
->sendOutputTo("/home/forge/dev.mysite.com/storage/logs/cron.log")
->emailWrittenOutputTo($email);
It laravel 5.2 though...
my basic problem was , I was passing string instead of array so, error was
->emailWrittenOutputTo('[email protected]'); // string, we need an array
Its because the email address which is being sent is blank. see those empty brackets? that means the email address is not being put in the $address of the swiftmailer function.
These error happen when the $email variable is empty or sometimes when the mail doesn´t exists, try with an existing mail
The only solution worked for me is changing the following code
Mail::send('emails.activation', $data, function($message){
$message->from(env('MAIL_USERNAME'),'Test');
$message->to($email)->subject($subject);
});
Your problem may be that the .env file is not loading properly and using the MAIL_USERNAME.
To check if your .env file is loading the email address properly add this line to your controller and refresh the page.
dd(env('MAIL_USERNAME')
If it shows up null try running the following command from command line and trying again.
php artisan cache:clear
Try this.
Mail::send('emails.activation', $data, function($message) use($email,$subject){
$message->to($email)->subject($subject);
});
->with('title', "Registered Successfully.");
(I'm using SwiftMailer in PHP)
I was getting an error like that when I was accidentally sending a string for $email
$email = "[email protected] <Some One>";
When what I meant to be sending was
$email = Array("[email protected]"=>"Some One");
I was accidentally running it through a stringify function that I was using for logging, so once I started sending the array again, the error went away.
Mail::send('emails.activation', $data, function($message){
$message->from('email@from', 'name');
$message->to($email)->subject($subject);
});
I dont know why, but in my case I put the from's information in the function and it's work fine.
Data variables ($email, $subject) seems to be global. And globals cannot be read inside functions. You must pass them as parameters (the recommended way) or declare them as global.
Try this way:
Mail::send('emails.activation', $data, function($message, $email, $subject){
$message->to($email)->subject($subject);
});
->with('title', "Registered Successfully.");
Make sure your email address variable is not blank. Check using
print_r($variable_passed);
Source: Stackoverflow.com