Skip to content

Commit

Permalink
feat(MailController, mail view) -start customizing mail view, create …
Browse files Browse the repository at this point in the history
…new function to handle the whole emailing process(wip)
  • Loading branch information
AliciaMV committed May 15, 2022
1 parent a7cdead commit 74f14f4
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 20 deletions.
32 changes: 29 additions & 3 deletions app/Http/Controllers/MailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Symfony\Component\HttpFoundation\Response;
//use App\Mail\ContactUser;
use App\Mail\SendEmail;
use App\Models\Users;
//use App\Models\Subscriber;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Validator;
Expand Down Expand Up @@ -36,8 +37,33 @@ public function send(Request $request)



public function hello()
{
return response()->json('hello');
public function hello()
{
return response()->json('hello');
}

public function contactUser(Request $request)
{
$senderId = $request->sender_user_id;
$receiverId = $request->receiver_user_id;
$messageContent = $request->message_content;

$senderInfo = Users::where('id', '=', $senderId)->select('firstname', 'email_address')->get();
$receiverInfo = Users::where('id', '=', $receiverId)->select('firstname', 'email_address')->get();

foreach ($senderInfo as $si) {
$senderName=$si->firstname;
$senderMail=$si->email_address;
}
foreach ($receiverInfo as $ri) {
$receiverName=$ri->firstname;
$receiverMail=$ri->email_address;
}


$monEmail = '[email protected]';
Mail::to($monEmail)->send(new SendEmail($monEmail, $senderName, $senderMail, $receiverName, $receiverMail, $messageContent));

return response()->json(['status' => 'success', 'message' => 'Email sent Successfully', 'data' => $monEmail]);
}
}
15 changes: 13 additions & 2 deletions app/Mail/SendEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,25 @@ class SendEmail extends Mailable
use Queueable, SerializesModels;

public $email;
public $senderName;
public $senderMail;
public $receiverName;
public $receiverMail;
public $messageContent;

/**
* Create a new message instance.
*
* @return void
*/
public function __construct($email)
public function __construct($email, $senderName, $senderMail, $receiverName, $receiverMail, $messageContent)
{
$this->email = $email;
$this->senderName = $senderName;
$this->senderMail = $senderMail;
$this->receiverName = $receiverName;
$this->receiverMail = $receiverMail;
$this->messageContent = $messageContent;
}

/**
Expand All @@ -30,7 +40,8 @@ public function __construct($email)
*/
public function build()
{
return $this->subject('test, test 1, 2, 1, 2')
//"\u{1F913}"
return $this->subject('Tu as reçu un nouveau message !')
->markdown('mails.contactUser');
}
}
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"aws/aws-sdk-php": "^3.222",
"flipbox/lumen-generator": "^9.1",
"guzzlehttp/guzzle": "^7.4",
"illuminate/contracts": "^8.83",
"illuminate/mail": "^8.83",
"illuminate/view": "^8.83",
"laravel/lumen-framework": "^8.3.1",
"laravelista/lumen-vendor-publish": "^8.0",
"nordsoftware/lumen-cors": "^3.5",
Expand Down
6 changes: 3 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added public/meetdevMail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 9 additions & 8 deletions resources/views/mails/contactUser.blade.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
@component('mail::message')
# Introduction
# Toc toc, on a du courrier pour toi !

Hello <b>{{ $email }}</b>,
Bonjour <b>{{ $receiverName }}</b>,

The body of your message.
{{$senderName}} t'a envoyé un message !

@component('mail::button', ['url' => ''])
Button Text
@component('mail::panel')
{{$messageContent}}
@endcomponent

Thanks,<br>
meetDev
@endcomponent
Tu peux lui répondre à l'adresse suivante: {{$senderMail}} .

En te souhaitant une bonne journée, <br>
L'équipe meetdev
@endcomponent
3 changes: 2 additions & 1 deletion resources/views/vendor/mail/html/header.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<tr>
<td class="header">
<td class="header-md">
<a href="{{ $url }}" style="display: inline-block;">

@if (trim($slot) === 'Laravel')
<img src="https://laravel.com/img/notification-logo.png" class="logo" alt="Laravel Logo">
@else
Expand Down
4 changes: 3 additions & 1 deletion resources/views/vendor/mail/html/message.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
{{-- Header --}}
@slot('header')
@component('mail::header', ['url' => config('app.url')])
{{ config('app.name') }}
<img src="{{url('http://localhost/MeetDev/projet-10-meet-dev-back/public/meetdevMail.png')}}" class="logo-md" alt="meetdev">
meetdev
<hr>
@endcomponent
@endslot

Expand Down
4 changes: 2 additions & 2 deletions resources/views/vendor/mail/html/panel.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<table class="panel" width="100%" cellpadding="0" cellspacing="0" role="presentation">
<table class="panel-md" width="100%" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td class="panel-content">
<td class="panel-content-md">
<table width="100%" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td class="panel-item">
Expand Down
42 changes: 42 additions & 0 deletions resources/views/vendor/mail/html/themes/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,37 @@ img {
text-decoration: none;
}

.header-md {
padding: 25px 0;
margin-left: 15px;
text-align: left;
margin-bottom: 15px;
padding-bottom: 15px;
}
.header-title-md {
position: relative;
margin-left: 20px;
font-size: 22px;
font-weight: bold;
text-decoration: none;
color: #ffffff;
opacity: 0.7;
}


/* Logo */

.logo {
height: 75px;
max-height: 75px;
width: 75px;
}
.logo-md {
height: 75px;
max-height: 75px;
width: 75px;
text-align: left;
}

/* Body */

Expand Down Expand Up @@ -283,8 +307,26 @@ img {
padding-bottom: 0;
}

.panel-md {
margin: 21px 0;
}
.panel-content-md {
background-color: #f2f5f9;
color: #718096;
padding: 16px;
}

/* Utilities */

.break-all {
word-break: break-all;
}


/* Other */

hr {
margin: 12px 0 0 -100px;
border-top: 0.5px solid #50c6b9;
width: 3000%;
}
13 changes: 13 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use App\Http\Controllers\MessagesController;
use App\Http\Controllers\UsersController;
use App\Http\Controllers\EmailController;
use App\Mail\SendEmail;



/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -84,7 +87,17 @@
$router->post('/login', 'UsersController@login');
$router->get('/send/email', 'MailController@send');
$router->get('/send/hello', 'MailController@hello');
$router->get('/contact', 'MailController@contactUser');

// $router->get('/search-results', 'UsersController@getDevSearchResults');
});

/*Route::get('/mailable', function () {
$email = "[email protected]";
$sm = new App\Mail\SendEmail($email);
$markdown = new \Illuminate\Mail\Markdown(View(), config('mail.markdown'));
//$data = "[email protected]";
return $markdown->render($sm->markdown);
});*/

0 comments on commit 74f14f4

Please sign in to comment.