0

I'm working right now with a Laravel 5.1, for some reason my code, even thou it looks fine, doesn't work properly.

I'm trying to make my app send an email with a view as a message.

public function sale(Request $request, $id)
{

    $laptops = Laptops::findOrFail($id);

    $name = Input::get('usr');
    $lname = Input::get('lname');
    $email = Input::get('email');
    $city = Input::get('city');
    $street = Input::get('street');
    $houseNr = Input::get('houseNr');
    $postCode = Input::get('postCode');
    $telephone = Input::get('telephone');
    $dCity = Input::get('deliveryCity');
    $dStreet = Input::get('deliveryStreet');
    $dHouseNr = Input::get('deliveryHouseNr');
    $dPostCode = Input::get('deliveryPostCode');
    $dTelephone = Input::get('deliveryTelephone');



    DB::table('orders')->insert([
    [
        'customerName' => Input::get('usr'),
        'customerLastname' => Input::get('lname'),
        'customerEmail' => Input::get('email'),
        'customerCity' => Input::get('city'),
        'customerStreet' => Input::get('street'),
        'customerHomeNumber' => Input::get('houseNr'),
        'customerPostNumber' => Input::get('postCode'),
        'customerPhoneNumber' => Input::get('telephone'),
        'customerDeliveryCity' => Input::get('deliveryCity'),
        'customerDeliveryStreet' => Input::get('deliveryStreet'),
        'customerDeliveryHomeNumber' => Input::get('deliveryHouseNr'),
        'customerDeliveryPostNumber' => Input::get('deliveryPostCode'),
        'customerDeliveryPhoneNumber' => Input::get('deliveryTelephone'),
        'choosenNotebook' => $laptops->name,
        'choosenGpu' => $laptops->gpu,
        'choosenCpu' => $laptops->cpu,
        'choosenRam' => $laptops->ram,
        'choosenHdd' => $laptops->hdd,
        'choosenSsd' => $laptops->ssd,
        'choosenAHdd' => $laptops->hdd2,
        'choosenASsd' => $laptops->ssd2,
        'choosenOs' => $laptops->os,
        'choosenWarranty' => $laptops->warrantyOption,
        'orderPrice' => $laptops->price,
    ]]);


    Mail::send('shop.message', ['name' => Input::get('usr'), 'lastname' => Input::get('lname')], function($message)
    {

        $message->to(Input::get('email'), Input::get('usr'))->from('support@dreammachines.pl')->subject('Informacje dotyczące sprzędaży.');

    });

    return view('shop.payment', compact('laptops', 'name', 'lname', 'email', 'city', 'street', 'houseNr', 'postCode', 'telephone', 'dCity', 'dStreet', 'dHouseNr', 'dPostCode', 'dTelephone'));

}

That's how my controller looks like right know, it basically gets the data from an input and fetch some other information from the database, then it is supposed to save that data in other table, (that'll be used to track some information for an app). After that it should send a message, but even thou my .env file is set up correctly I'm not receiving any emails. Rest of the code works as I wanted it to.

Any idea what might make this script not working?

chanafdo
  • 5,016
  • 3
  • 29
  • 46
  • From what you posted, we can't determine *which* service is being used for emailing. Is it PHP's `mail` (which depends on having postfix installed locally) or is it a service like `Mailgun` etc. – Mjh Dec 02 '15 at 11:01
  • The first thing to check is always the application logs. Are you using a local driver (e.g. sendmail) to send, or are you calling some API like Mailgun? If it's the first, check the mail logs - normally `/var/log/mail.log` - to make sure that the app even attempts to send mail. If using an API, check their logs, try to send mail manually via `curl` and see what happens. – kalatabe Dec 02 '15 at 11:01
  • can u please post the error getting. – Jishad P Dec 02 '15 at 11:06
  • Service I'm using is 'Illuminate\Support\Facades\Mail;', as for the driver it's just a smtp. There are no errors showing up. Everything runs nicely except for those mails that didn't get sent. I've been trying to use a SendMail previously, but it doesn't seem to work very well on Windows for me. – Kuba Biały Dec 02 '15 at 11:45
  • Start by checking the Laravel log file. Also check if `pretend` is set to `true` under mail configuration. – chanafdo Dec 03 '15 at 08:03
  • which smtp provider are you using, gmail ? can you show us your mail config? – Vikas Dec 08 '15 at 07:42

1 Answers1

0

Use PHPMailer, if you are doing it in the local it wont work.PHPMailer will configure your php.ini file and then you will surely get the mail.

vikram mistry
  • 106
  • 1
  • 7