无法使用laravel中的控制器发送抄送

时间:2019-07-07 08:47:45

标签: php html sql laravel

我在laravel中有表单,当用户提交表单时,数据进入数据库和我的电子邮件中。它的工作正常。现在,我希望将一份副本或成功的消息发送给提交该消息的特定用户。我在控制器中尝试了以下操作:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Register;
use App\Mail\SendEmail;
use Session;
use Mail;
use Storage;
use Illuminate\Support\Facades\File;

class RegController extends Controller
{

    public function index()
    {
        //
    }


    public function create()
    {
        //
    }

    public function store(Request $request)
    {

       // return $request;


// return $request->Fee;
            $data = new Register;
            $data->firstname = $request->firstname;
            $data->lastname = $request->lastname;
            $data->mobilenumber = $request->mobilenumber;
            $data->experience = $request->experience;
            $data->designation = $request->designation;
            $data->confirmation = $request->confirmation;
            $data->company = $request->company;
            $data->address = $request->address;
            $data->addressline2 = $request->addressline2;
            $data->city = $request->city;
            $data->state = $request->state;
            $data->pin = $request->pin;
            $data->country = $request->country;
            $data->Whatsapp = $request->Whatsapp;
            $data->alternatenumber = $request->alternatenumber;
            $data->Email = $request->Email;
            $data->CompanyRegNumber = $request->CompanyRegNumber;
            $data->Date_Incorporation_orBusi_Stp = $request->Date_Incorporation_orBusi_Stp;
            $data->GSTIN = $request->GSTIN;
            $data->Services_Offered = $request->Services_Offered;
            $data->Annual_Turnover = $request->Annual_Turnover;
            $data->Declaration = $request->Declaration;
            $data->Fee = $request->Fee;

            $data->termsandconditions = $request->termsandconditions;
            // $data->Fee = $request->Fee;
            $data->Mode_of_Payment = $request->Mode_of_Payment;

            $data->Recommended_by_A = $request->Recommended_by_A;
            $data->Recommended_by_B = $request->Recommended_by_B;




 if($request->hasFile('Photo')) {
      $image = $request->file('Photo');
      $filename = time().$image->getClientOriginalName();
      $destinationPath = public_path('uploads/Photo');

     Storage::disk('public')->put($filename,  File::get($image));
      $data->Photo=$filename;
    }
 if($request->hasFile('Receipt')) {
      $image = $request->file('Receipt');
      $filename = time().$image->getClientOriginalName();
      $destinationPath = public_path('uploads/Receipt');
    Storage::disk('public')->put($filename,  File::get($image));
      $data->Receipt=$filename;
    }
 if($request->hasFile('Signature')) {
      $image = $request->file('Signature');
      $filename = time().$image->getClientOriginalName();
      $destinationPath = public_path('uploads/Signature');
      Storage::disk('public')->put($filename,  File::get($image));
      $data->Signature=$filename;
    }

            $data->save();
            Session::flash('registered','reg');


        $name = $request->firstname." ".$request->lastname;
        $subject = "TEIA";
        $message =  $data->id;

         $photo = $data->Photo;
         $sign = $data->Signature;
         $recipt= $data->Receipt;
         $email = 'teiamembers@gmail.com';



         
      Mail::to($email)
      ->cc(['$reg->Email')
      ->send( new SendEmail($subject,$message , $photo ,$sign,$recipt));


                  //
                  // return redirect('demo')->with(['reg'=>$data]);

            return redirect('formdata');
    }


    public function show($id)
    {
        //
    }


    public function edit($id)
    {
        //
    }


    public function update(Request $request, $id)
    {
        //
    }


    public function destroy($id)
    {
        //
    }
}

,但不起作用。谁能告诉我如何正确发送抄送?

1 个答案:

答案 0 :(得分:0)

您的cc电子邮件地址似乎不正确。应该是:

...
->cc($request->email)
...

email是html表单输入元素的名称。相应地更改它。

优良作法是通过队列发送电子邮件,以获得更好的用户体验。