我有一个正确的电子邮件地址。我已经回应了它,但是当我发送它时,我收到以下错误:
Address in mailbox given [] does not comply with RFC 2822, 3.6.2.
为什么?我使用laravel(swift mailer)发送电子邮件:
$email = [email protected]
然后当我发送它时,错误被抛出。
但如果我直接使用该字符串,它会发送它。
这是块:
Mail::send('emails.activation', $data, function($message){
$message->to($email)->subject($subject);
});
->with('title', "Registered Successfully.");
由于范围的原因,您的电子邮件变量为空,您应该设置一个use子句,例如:
Mail::send('emails.activation', $data, function($message) use ($email, $subject) {
$message->to($email)->subject($subject);
});
我今天遇到了类似的问题,解决方案就像它一样。
$email = Array("Zaffar Saffee" => "[email protected]");
$schedule->command('cmd:mycmd')
->everyMinute()
->sendOutputTo("/home/forge/dev.mysite.com/storage/logs/cron.log")
->emailWrittenOutputTo($email);
它虽然laravel 5.2 ...
我的基本问题是,我传递字符串而不是数组,所以错误是
->emailWrittenOutputTo('[email protected]'); // string, we need an array
[求助] Neos / swiftmailer:给[]邮箱中的地址不符合RFC 2822,3.6.2
/var/www/html/vendor/Packages/Libraries/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php第261行中的异常:给定[]的邮箱中的地址不符合RFC 2822,3.6 0.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.'
);
}
}
您的问题可能是.env文件未正确加载并使用MAIL_USERNAME。
要检查.env文件是否正在加载电子邮件地址,请将此行添加到控制器并刷新页面。
dd(env('MAIL_USERNAME')
如果它显示为null,请尝试从命令行运行以下命令并再次尝试。
php artisan cache:clear
(我在PHP中使用SwiftMailer)
当我不小心为$ email发送字符串时,我收到了类似的错误
$email = "[email protected] <Some One>";
当我打算发送的是
$email = Array("[email protected]"=>"Some One");
我不小心通过我用于记录的stringify函数运行它,所以一旦我再次开始发送数组,错误就消失了。
确保您的电子邮件地址变量不为空。检查使用
的print_r($ variable_passed);
我遇到了同样的问题,我已经修好了。请确保一些事情如下所示:
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 !');
});
这应该是你的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>
----
为什么你不能将$ email变量调用到你的邮件发送功能的答案。您需要调用$ user变量,然后您可以将所需的变量写为$ user-> variable
谢谢 :)
Mail::send('emails.activation', $data, function($message){
$message->from('email@from', 'name');
$message->to($email)->subject($subject);
});
我不知道为什么,但在我的情况下,我将from的信息放在函数中,并且它工作正常。
这是因为发送的电子邮件地址是空白的。看到那些空括号?这意味着电子邮件地址没有放在swiftmailer函数的$地址中。
数据变量($ email,$ subject)似乎是全球性的。并且全局变量无法在函数内部读取。您必须将它们作为参数传递(推荐方式)或将它们声明为全局。
试试这种方式:
Mail::send('emails.activation', $data, function($message, $email, $subject){
$message->to($email)->subject($subject);
});
->with('title', "Registered Successfully.");
当$ email变量为空或有时当邮件不存在时,会发生这些错误,请尝试使用现有邮件
试试这个。
Mail::send('emails.activation', $data, function($message) use($email,$subject){
$message->to($email)->subject($subject);
});
->with('title', "Registered Successfully.");