lundi 1 mars 2021

how can I pass the 'customer address' to my new Mailer instance?

I am making a dynamic sender, I put this code in a Service class**(AppServiceProvider.php)** or in a function that returns the Mailer object ready to be used.

 public function register()
{
    $this->app->bind('user.id', function ($app, $parameters) {
        $smtp_host = array_get($parameters, 'smtp_host');
        $smtp_port = array_get($parameters, 'smtp_port');
        $smtp_username = array_get($parameters, 'smtp_username');
        $smtp_password = array_get($parameters, 'smtp_password');
        $smtp_encryption = array_get($parameters, 'smtp_encryption');
      
        $from_email = array_get($parameters, 'from_email');
        $from_name = array_get($parameters, 'from_name');
      
        $from_email = $parameters['from_email'];
        $from_name = $parameters['from_name'];
      
        $transport = new \Swift_SmtpTransport($smtp_host, $smtp_port);
        $transport->setUsername($smtp_username);
        $transport->setPassword($smtp_password);
        $transport->setEncryption($smtp_encryption);
      
        $swift_mailer = new \Swift_Mailer($transport);
      
        //$mailer = new Mail;
        $mailer = new Mailer($app->get('view'), $swift_mailer, $app->get('events'));
        $mailer->alwaysFrom($from_email, $from_name);
        $mailer->alwaysReplyTo($from_email, $from_name);
      
        return $mailer;
    });
}

this is my controller where I pass the arguments to the new instance 'mailer'.

public function email(DocumentEmailRequest $request)
{
    $user = Company::active();
    $company = Company::active();
    $document = Document::find($request->input('id'));
    $customer_email = $request->input('customer_email');

    $configuration = [
        'smtp_host'    => 'smtp.gmail.com',
        'smtp_port'    => '465',
        'smtp_username'  => 'email@gmail.com',
        'smtp_password'  => 'password',
        'smtp_encryption'  => 'ssl',
       
        'from_email'    => 'email@gmail.com',
        'from_name'    => 'name',
       ];
       
    $mailer = app()->makeWith('user.id', $configuration);
    
    $mailer->to($customer_email)->send(new DocumentEmail($company, $document));

        return [
        'success' => true
    ];
}

I get this error:

"Swift_RfcComplianceException" exception. line: 355 message: "The given mailbox address [] does not comply with RFC 2822, 3.6.2.


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3uGAX8J
via IFTTT

Aucun commentaire:

Enregistrer un commentaire