mardi 6 novembre 2018

Unable to send an email in Mail::raw with get request email address variable

Herewith I'm using 'Mail::raw()' to send and email in Laravel - PHP. After getting request from the database, I assigned the receiver's email address to '$email'. In this case '$message->to('$email');' given an error 'Address in mailbox given [$email] does not comply with RFC 2822, 3.6.2.'. Instead of '$email', 'abcdef@test.com' its working perfectly. And also inside the 'Mail::row()' function, unable to get request values instead of hard code email address. Below is the code.

Controller.php

public function sendEmailToUser(Request $request)
    {
    $email = (String)$request->get('email');
    $messageBody = $request->get('password');

    $response = null;
    $res_type = null;

    \Mail::raw($messageBody, function ($message) {
        $message->from('abcd@gmail.com', 'TESTING');
        $message->to('$email');
        $message->subject('TESTING TITLE');
    });

    // check for failures
    if (\Mail::failures()) 
    {
        $response ="Email sent unsuccess";
        $res_type = 'warning';
    }
    else
    {
        $response ="Email sent successful";
        $res_type = 'success';

    }

    return redirect()->back()->with($response,$res_type);
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire