menu

Questions & Answers

AWS SES Address in mailbox given [] does not comply with RFC 2822, 3.6.2

When I am using a normal SMTP server such as mailtrap all my emails are working fine, but when I started using AWS SES SMTP, which has production access, I started to getting below error

Swift_RfcComplianceException Object(
[message:protected] => Address in mailbox given [] does not comply with RFC 2822, 3.6.2.
[string:Exception:private] => 
[code:protected] => 0
[file:protected] => /var/www/html/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php
[line:protected] => 355
[trace:Exception:private] => Array

My code is ForgotPasswordController

<?php

namespace Webkul\Customer\Http\Controllers;

use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
use Illuminate\Support\Facades\Password;
use Webkul\Customer\Http\Requests\CustomerForgotPasswordRequest;

class ForgotPasswordController extends Controller
{
    use SendsPasswordResetEmails;

    /**
     * Contains route related configuration.
     *
     * @var array
     */
    protected $_config;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->_config = request('_config');
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\View\View
     */
    public function create()
    {
        return view($this->_config['view']);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @return \Illuminate\Http\Response
     */
    public function store(CustomerForgotPasswordRequest $request)
    {
        $request->validated();
        if ($request->ajax()) {
            try {
            print_r (env('MAIL_USERNAME'));
                $response = $this->broker()->sendResetLink($request->only(['email']));

                if ($response == Password::RESET_LINK_SENT) {
                    return response()->json(['success' => true, 'message' => trans('customer::app.forget_password.reset_link_sent')]);
                }

                return response()->json(['success' => false, 'message' => trans('customer::app.forget_password.email_not_exist')]);
            } catch (\Swift_RfcComplianceException $e) {
             report($e);
                echo "<pre>";
                print_r($e); die;
                return response()->json(['success' => false, 'message' => trans('customer::app.forget_password.reset_link_sent')]);
            
            } catch (\Exception $e) {
                report($e);
                echo "<pre>";
                print_r($e); die;
                return response()->json(['success' => false, 'message' => trans($e->getMessage())]);

            }
        } else {
            try {
                $response = $this->broker()->sendResetLink($request->only(['email']));

                if ($response == Password::RESET_LINK_SENT) {
                    session()->flash('success', trans('customer::app.forget_password.reset_link_sent'));

                    return back();
                }

                return back()
                    ->withInput($request->only(['email']))
                    ->withErrors([
                        'email' => trans('customer::app.forget_password.email_not_exist'),
                    ]);
            } catch (\Swift_RfcComplianceException $e) {
                session()->flash('success', trans('customer::app.forget_password.reset_link_sent'));

                return redirect()->back();
            } catch (\Exception $e) {
                report($e);

                session()->flash('error', trans($e->getMessage()));

                return redirect()->back();
            }
        }
    }

    /**
     * Get the broker to be used during password reset.
     *
     * @return \Illuminate\Contracts\Auth\PasswordBroker
     */
    public function broker()
    {
        return Password::broker('customers');
    }
}

SMTP setting are

MAIL_MAILER=smtp
MAIL_HOST=email-smtp.us-east-1.amazonaws.com
MAIL_POR=587
MAIL_USERNAME=username as per SES
MAIL_PASSWORD=password as per ses
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=info@mydomain.com
MAIL_FROM_NAME="${APP_NAME}"

Logs are

[2022-12-26 13:10:01] prod.ERROR: Address in mailbox given [] does not comply with RFC 2822, 3.6.2. {"exception":"[object] (Swift_RfcComplianceException(code: 0): Address in mailbox given [] does not comply with RFC 2822, 3.6.2. at /var/www/html/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php:355)
[stacktrace]
#0 /var/www/html/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php(272): Swift_Mime_Headers_MailboxHeader->assertValidAddress()
#1 /var/www/html/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php(117): Swift_Mime_Headers_MailboxHeader->normalizeMailboxes()
#2 /var/www/html/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php(74): Swift_Mime_Headers_MailboxHeader->setNameAddresses()
#3 /var/www/html/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/SimpleMimeEntity.php(600): Swift_Mime_Headers_MailboxHeader->setFieldBodyModel()
#4 /var/www/html/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/SimpleMessage.php(213): Swift_Mime_SimpleMimeEntity->setHeaderFieldModel()
#5 /var/www/html/vendor/laravel/framework/src/Illuminate/Mail/Message.php(50): Swift_Mime_SimpleMessage->setFrom()
#6 /var/www/html/vendor/laravel/framework/src/Illuminate/Notifications/Channels/MailChannel.php(188): Illuminate\\Mail\\Message->from()
#7 /var/www/html/vendor/laravel/framework/src/Illuminate/Notifications/Channels/MailChannel.php(161): Illuminate\\Notifications\\Channels\\MailChannel->addSender()
#8 /var/www/html/vendor/laravel/framework/src/Illuminate/Notifications/Channels/MailChannel.php(135): Illuminate\\Notifications\\Channels\\MailChannel->addressMessage()
#9 /var/www/html/vendor/laravel/framework/src/Illuminate/Notifications/Channels/MailChannel.php(80): Illuminate\\Notifications\\Channels\\MailChannel->buildMessage()
#10 /var/www/html/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(271): Illuminate\\Notifications\\Channels\\MailChannel->Illuminate\\Notifications\\Channels\\{closure}()
#11 /var/www/html/vendor/laravel/framework/src/Illuminate/Notifications/Channels/MailChannel.php(65): Illuminate\\Mail\\Mailer->send()
#12 /var/www/html/vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php(148): Illuminate\\Notifications\\Channels\\MailChannel->send()
#13 /var/www/html/vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php(106): Illuminate\\Notifications\\NotificationSender->sendToNotifiable()
#14 /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Traits/Localizable.php(19): Illuminate\\Notifications\\NotificationSender->Illuminate\\Notifications\\{closure}()
#15 /var/www/html/vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php(109): Illuminate\\Notifications\\NotificationSender->withLocale()
#16 /var/www/html/vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php(79): Illuminate\\Notifications\\NotificationSender->sendNow()
#17 /var/www/html/vendor/laravel/framework/src/Illuminate/Notifications/ChannelManager.php(39): Illuminate\\Notifications\\NotificationSender->send()
#18 /var/www/html/vendor/laravel/framework/src/Illuminate/Notifications/RoutesNotifications.php(18): Illuminate\\Notifications\\ChannelManager->send()
#19 /var/www/html/packages/Webkul/Customer/src/Models/Customer.php(79): Webkul\\Customer\\Models\\Customer->notify()
#20 /var/www/html/vendor/laravel/framework/src/Illuminate/Auth/Passwords/PasswordBroker.php(71): Webkul\\Customer\\Models\\Customer->sendPasswordResetNotification()
#21 /var/www/html/packages/Webkul/Customer/src/Http/Controllers/ForgotPasswordController.php(51): Illuminate\\Auth\\Passwords\\PasswordBroker->sendResetLink()
#22 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): Webkul\\Customer\\Http\\Controllers\\ForgotPasswordController->store()
#23 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\\Routing\\Controller->callAction()
#24 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(254): Illuminate\\Routing\\ControllerDispatcher->dispatch()
#25 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(197): Illuminate\\Routing\\Route->runController()
#26 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(695): Illuminate\\Routing\\Route->run()
#27 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}()
#28 /var/www/html/packages/Webkul/Shop/src/Http/Middleware/HtmlMinifier.php(12): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#29 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Webkul\\Shop\\Http\\Middleware\\HtmlMinifier->handle()
#30 /var/www/html/packages/Webkul/Shop/src/Http/Middleware/Currency.php(46): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#31 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Webkul\\Shop\\Http\\Middleware\\Currency->handle()
#32 /var/www/html/packages/Webkul/Shop/src/Http/Middleware/Theme.php(31): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#33 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Webkul\\Shop\\Http\\Middleware\\Theme->handle()
#34 /var/www/html/packages/Webkul/Shop/src/Http/Middleware/Locale.php(50): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#35 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Webkul\\Shop\\Http\\Middleware\\Locale->handle()
#36 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#37 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle()
#38 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(78): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#39 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle()
#40 /var/www/html/vendor/laravel/framework/src/Illuminate/Session/Middleware/AuthenticateSession.php(39): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#41 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Session\\Middleware\\AuthenticateSession->handle()
#42 /var/www/html/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#43 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle()
#44 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#45 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(697): Illuminate\\Pipeline\\Pipeline->then()
#46 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(672): Illuminate\\Routing\\Router->runRouteWithinStack()
#47 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(636): Illuminate\\Routing\\Router->runRoute()
#48 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(625): Illuminate\\Routing\\Router->dispatchToRoute()
#49 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(166): Illuminate\\Routing\\Router->dispatch()
#50 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}()
#51 /var/www/html/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(59): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#52 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Barryvdh\\Debugbar\\Middleware\\InjectDebugbar->handle()
#53 /var/www/html/packages/Webkul/Core/src/Http/Middleware/SecureHeaders.php(30): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#54 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Webkul\\Core\\Http\\Middleware\\SecureHeaders->handle()
#55 /var/www/html/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#56 /var/www/html/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\\Session\\Middleware\\StartSession->handleStatefulRequest()
#57 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Session\\Middleware\\StartSession->handle()
#58 /var/www/html/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#59 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle()
#60 /var/www/html/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(67): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#61 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Cookie\\Middleware\\EncryptCookies->handle()
#62 /var/www/html/packages/Webkul/Core/src/Http/Middleware/CheckForMaintenanceMode.php(114): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#63 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Webkul\\Core\\Http\\Middleware\\CheckForMaintenanceMode->handle()
#64 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#65 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(141): Illuminate\\Pipeline\\Pipeline->then()
#66 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(110): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter()
#67 /var/www/html/public/index.php(88): Illuminate\\Foundation\\Http\\Kernel->handle()
#68 {main}
"} 

UPDATE

If I try another way for sending email it worked.

$data = array('name'=>"urfusion");
                Mail::send([], [], function($message) {
         $message->to('urfusion@urfusion.net', 'urfusion')->subject
            ('Mail');
         $message->from('info@domain.com','domain');
      });
Comments:
2023-01-18 23:30:07
stackoverflow.com/help/minimal-reproducible-example open your laravel.log, find the error and copy the entire stacktrace for that error. You need to find the details of the mail you're sending with SES and try to do that by dd-ing as much as possible
2023-01-18 23:30:07
I would try to use SES locally as well. You probably used mailtrap, but you need to prevent the "it works on my machine" part, after you put your code on the production server
2023-01-18 23:30:07
For now, focus on /packages/Webkul/Customer/src/Models/Customer.php(79), can you copy/paste that function? It's the notify() function
2023-01-18 23:30:07
Also focus on this function: /var/www/html/packages/Webkul/Customer/src/Http/Controllers/‌​ForgotPasswordContro‌​ller.php(51), it's the sendResetLink() function or something like that
2023-01-18 23:30:07
It's up to you to make a minimal reproducible example: stackoverflow.com/help/minimal-reproducible-example it's fine, that it's on github, but when you look at the notify function, it dispatches an event. So your reproducible example is copy the tiny pieces that are giving you your problem. Just don't show the link like: "well, here's the entire project, my problem is in there somewhere"
Answers(0) :