Posted on: November 04, 2020 05:10 PM
Posted by: Renato
Categories: Laravel
Views: 3006
Erro besta que pode atrapalhar seu desenvolvimento do codigo.
`laravel error Address in mailbox given [] does not comply with RFC 2822, 3.6.2.,`
```
[2020-11-04 18:14:50] local.ERROR: Address in mailbox given [Xsensors] does not comply with RFC 2822, 3.6.2. {"exception":"[object] (Swift_RfcComplianceException(code: 0): Address in mailbox given [Xsensors] does not comply with RFC 2822, 3.6.2. at /var/www/ainda-api/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php:355)
[stacktrace]
#0 /var/www/ainda-api/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php(272): Swift_Mime_Headers_MailboxHeader->assertValidAddress('Xsensors')
#1 /var/www/ainda-api/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php(117): Swift_Mime_Headers_MailboxHeader->normalizeMailboxes(Array)
#2 /var/www/ainda-api/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php(74): Swift_Mime_Headers_MailboxHeader->setNameAddresses(Array)
#3 /var/www/ainda-api/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/SimpleMimeEntity.php(600): Swift_Mime_Headers_MailboxHeader->setFieldBodyModel(Array)
#4 /var/www/ainda-api/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/SimpleMessage.php(213): Swift_Mime_SimpleMimeEntity->setHeaderFieldModel('From', Array)
#5 /var/www/ainda-api/vendor/laravel/framework/src/Illuminate/Mail/Message.php(50): Swift_Mime_SimpleMessage->setFrom(Array, 'Ainda Studio')
#6 /var/www/ainda-api/vendor/laravel/framework/src/Illuminate/Mail/Mailable.php(328): Illuminate\\Mail\\Message->from('Xsensors', 'Ainda Studio')
#7 /var/www/ainda-api/vendor/laravel/framework/src/Illuminate/Mail/Mailable.php(154): Illuminate\\Mail\\Mailable->buildFrom(Object(Illuminate\\Mail\\Message))
#8 /var/www/ainda-api/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(244): Illuminate\\Mail\\Mailable->Illuminate\\Mail\\{closure}(Object(Illuminate\\Mail\\Message))
#9 /var/www/ainda-api/vendor/laravel/framework/src/Illuminate/Mail/Mailable.php(159): Illuminate\\Mail\\Mailer->send('emails.contact', Array, Object(Closure))
#10 /var/www/ainda-api/vendor/laravel/framework/src/Illuminate/Support/Traits/Localizable.php(19): Illuminate\\Mail\\Mailable->Illuminate\\Mail\\{closure}()
#11 /var/www/ainda-api/vendor/laravel/framework/src/Illuminate/Mail/Mailable.php(160): Illuminate\\Mail\\Mailable->withLocale(NULL, Object(Closure))
#12 /var/www/ainda-api/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(277): Illuminate\\Mail\\Mailable->send(Object(Illuminate\\Mail\\Mailer))
#13 /var/www/ainda-api/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(231): Illuminate\\Mail\\Mailer->sendMailable(Object(App\\Mail\\ContactUs))
#14 /var/www/ainda-api/vendor/laravel/framework/src/Illuminate/Mail/PendingMail.php(122): Illuminate\\Mail\\Mailer->send(Object(App\\Mail\\ContactUs))
#15 /var/www/ainda-api/app/Jobs/SendMailJob.php(160): Illuminate\\Mail\\PendingMail->send(Object(App\\Mail\\ContactUs))
#16 /var/www/ainda-api/app/Jobs/SendMailJob.php(60): App\\Jobs\\SendMailJob->SendMailContact(Array)
#17 [internal function]: App\\Jobs\\SendMailJob->handle()
```
Laravel PassportControlller
public function sendEmailContact(Request $request)
{
$validator = Validator::make($request->all(), [
'full_name' => 'required',
'email' => 'required',
'subject' => 'required',
'business' => 'nullable',
'phone' => 'required',
'content' => 'required',
]);
if ($validator->fails()) {
return response()->json(['error' => $validator->errors()], 403);
}
$params = $request->all();
$content = $params['content'];
$subject = $params['subject'];
$full_name = $params['full_name'];
$email = $params['email'];
$business = $params['business'];
$phone = $params['phone'];
$emailto = Platform::getContactEmail();
$emailfrom = Platform::getNoreplyEmail();
$type = 'contact';
$params = [];
$params = [
'emailto' => $emailto,
'emailfrom' => $emailfrom,
'content' => $content,
'subject' => $subject,
'full_name' => $full_name,
'email' => $email,
'business' => $business,
'phone' => $phone
];
$this->dispatch(new SendMailJob($params, $type));
return response()->json(['success' => 200], 200);
}
Depois SendMailJob
public function SendMailContact($params)
{
//dump($params);
Mail::to($params['emailto'])->send(new ContactUs(
$params['content'],
$params['subject'],
$params['full_name'],
$params['email'],
$params['emailfrom'],
$params['business'],
$params['phone']
));
}
Depois Mail/ContactUs.php
class ContactUs extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($email_content, $email_subject, $email_full_name, $email, $email_from, $business, $phone)
{
$this->email_content = $email_content;
$this->email_subject = $email_subject;
$this->email_full_name = $email_full_name;
$this->email = $email;
$this->email_from = $email_from;
$this->business = $business;
$this->phone = $phone;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from($this->email_from, Platform::getName())
->view('emails.contact', ['content' => $this->email_content, 'full_name'=> $this->email_full_name, 'email' => $this->email, 'subject'=> $this->email_subject, 'business' => $this->business, 'phone' => $this->phone])
->subject($this->email_subject);
}
}
Por final o Blade do email
<table style="width:650px; font-family: 'Roboto', sans-serif;" cellpadding="0" cellspacing="0" align="center">
<tr>
<td>
<b>Name:</b> {{$full_name}}
</td>
</tr>
<tr>
<td>
<b>E-mail:</b> {{$email}}
</td>
</tr>
<tr><td></td></tr>
<tr>
<td>
<b>Subject:</b> {{$subject}}
</td>
</tr>
<tr><td></td></tr>
<tr>
<td>
<b>Business:</b> {{$business}}
</td>
</tr>
<tr><td></td></tr>
<tr>
<td>
<b>Phone:</b> {{$phone}}
</td>
</tr>
<tr><td></td></tr>
<tr>
<td>
<span> </span>
<br/>
<p>{{$content}}</p>
</td>
</tr>
</table>
A solução era somente acerta a orderm do SendMailJob que enviava para ContactUs, era somente colocar na mesma orderm.
Fiquem esperto para não perderem tempo pesquisando no google o que poder ser este erro.
É isso, dicas rápidas, mas espero que úteis!
Donate to Site
Renato
Developer