Saturday, September 3, 2016

Sending Email Using SMTP-GMAIL in Laravel 5.3 - Part II

In the previous post, we have sent an email using Mail::raw, so in this post we are going to use another method, Mail::send, with it's another properties. First... Let's change our Mail::raw to Mail:send as shown below :

Next... Let's create our emailcontent within view folder :
Yaaaps.... That's all... Let's hit "Send Mail" link {turn off antivirus first}...
Aaand... Here is our email...
Next, let's some properties to our email so change the Mail::send to be like this :
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use Log;
use Mail;

class emailcontroller extends Controller
{
    public function defaultSend()
    {
        Log::info("Request cycle without Queues started");

        Mail::send('emailcontent', ['data'=>'data'], function ($message) {
            $message->subject("Default Email");
            $message->from('adiatstei07@gmail.com', 'Hisoka');
            $message->to('hyosoka187@gmail.com');
            $message->cc('maryadi@astrnt.co');
            $message->attachData('This is my pdf Data...','hisoka.pdf');
            log::info("End of mail processing...");
        });


        Log::info("Request cycle without Queues finished");
        return redirect()->back();

    }
}

Result is like this :
Yeepp... That's all for this second part... :D... B-)
Demo :


Source code:
https://github.com/HyosokaPoipo/maillaravel53/tree/1._Part_2

Sending Email Using SMTP-GMAIL in Laravel 5.3

I'm using xampp windows 7 for sending this email in laravel. Sooo... mmm... Let's get started... :D
1. Set-up your laravel environment, you can take a look at this post...
2. Create your own view, for me it's just as simple like this: :D :D
3. Change laravel config on .env file like this :

4. Next..... let's create our controller and route....


5. Turn off your antivirus{because I'm using port 587} in order to prevent SSL issue in windows 7 and then run your laravel server then hit the send button... :D aaaaan...d....
You will get the email....
Actually... If you got an error like username and password not accepted in gmail, then you can see my post here to solve it... ;)


Here is the demo...

Source code :
https://github.com/HyosokaPoipo/maillaravel53


Go to Part II...