lundi 27 avril 2020

How to switch destination mail address by selecting check box in Laravel contact form

This is conctact form and sorking. I would like to switch email destination by User selecting check box.

For example. Here is a coulumn called 'genders'. When User check 'man' select box, Email destination will be [TO]'man_survey@12345677.site' and [CC] is 'man_cc_survey@12345677.site'. When User check 'female' ,Email destination will be [TO] 'female_survey@12345677.site' and [CC] is 'female_cc_survey@12345677.site'

Could you teach me how to add this function to my current code?

my Laravel Framework is 5.7.28

<?php

namespace App\Http\Controllers;

use App\Http\Requests\ContactRequest;
use App\Http\Controllers\Controller;
use App\Contact;

class ContactsController extends Controller
{

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $types = Contact::$types;
        $genders = Contact::$genders;


        return view('contacts.index', compact('types', 'genders'));
    }

    public function confirm(ContactRequest $request)
    {
        $contact = new Contact($request->all());


        $type = '';
        if (isset($request->type)) {
            $type = implode(', ',$request->type);
        }

        return view('contacts.confirm', compact('contact', 'type'));
    }

    public function complete(ContactRequest $request)
    {
        $input = $request->except('action');

        if ($request->action === 'back') {
            return redirect()->action('ContactsController@index')->withInput($input);        }


        if (isset($request->type)) {
            $request->merge(['type' => implode(', ', $request->type)]);
        }


        // store data
        Contact::create($request->all());

        // send mail
        \Mail::send(new \App\Mail\Contact([
            'to' => $request->email,
            'to_name' => $request->name,
            'from' => 'survey@12345677.site',
            'from_name' => 'from name',
            'subject' => 'Thank you',
            'type' => $request->type,
            'gender' => $request->gender,
            'body' => $request->body
        ]));

        // recive mail
        \Mail::send(new \App\Mail\Contact([
            'to' => 'survey@12345677.site',
            'to_name' => 'to name',
            'from' => $request->email,
            'from_name' => $request->name,
            'subject' => 'you got mail',
            'type' => $request->type,
            'gender' => $request->gender,
            'body' => $request->body
        ], 'from'));


        return view('contacts.complete');
    }
}


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2SbGcMb
via IFTTT

Aucun commentaire:

Enregistrer un commentaire