Monday, March 20, 2017

Laravel 5.4 : Variables become NULL when sent via E-mail

i have a website that encrypts, and decrypts data that is entered to a text-box, when i click on "encrypt" the application will send an Email containing the encrypted message.

the problem : the email contains everything, EXCEPT the actual encrypted message.

i'm using mailtrap to view the sent emails. here's the code :

the controller:

public function encrypt(Request $request){
    $output = encrypt($request->name);
    Mail::to('kevin@example.com')->send(new EncryptionSent($output));

    return view('decrypt', ['output' => $output,]);
}

The Mailables :

class EncryptionSent extends Mailable{
use Queueable, SerializesModels;

public $output;

public function __construct($message){
    global $output;
    $output = $message;
}
public function build(){
    global $output;
    return $this->from('example@example.com')->view('decrypt', ['output' => $output,]);
}

}

The View :

@extends ('home')
@section('content')
<div  style = "width: 250px;border: 1px solid #000000;word-wrap:break-word">
<!-- The Decrypted code is located here -->

</div>

<form action="" method="POST" class="form-    horizontal">
    
    <br/><br/>
    <button type="submit" class="btn btn-default">
        <i class="fa fa-btn fa-plus"></i> Decrypt!
    </button>
</form>

@endsection

i used dd() to find out the problem, but $output always returns the encrypted message in the controller and mailables.

thanks for reading, hoping that someone can help!



via Kevin fu

Advertisement