无法在 laravel 中使用控制器发送 cc
Posted
技术标签:
【中文标题】无法在 laravel 中使用控制器发送 cc【英文标题】:not able to send cc using controller in laravel 【发布时间】:2019-11-17 03:00:16 【问题描述】:我在 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)
//
但它不起作用。谁能告诉我如何正确发送抄送?
【问题讨论】:
->cc(['$reg->Email')
打错字了?或者这是你的实际代码?你在这里遇到什么错误?
$reg
变量从何而来?
@hassan 在我的 sendmail.php 我使用 $reg->Email 向浏览器显示电子邮件.. 实际上我的表单 html 是 ...
@hassan 我应该在那里实际使用什么来检索电子邮件字段
我觉得你需要->cc($request->Email)
【参考方案1】:
您的cc
电子邮件地址似乎不正确。应该是:
...
->cc($request->email)
...
email
是您的 html 表单输入元素的名称。相应地更改它。
最好通过队列发送电子邮件以获得更好的用户体验。
【讨论】:
以上是关于无法在 laravel 中使用控制器发送 cc的主要内容,如果未能解决你的问题,请参考以下文章