简体   繁体   中英

Laravel won't send email

I have set my email function and I can get my form data but not able to send them,

Error I get

Undefined variable: name 

My form data dd

array:6 [▼
  "name" => "tester"
  "email" => "test@test.com"
  "subject" => "testing emails"
  "issue" => "Other"
  "budget" => "100"
  "messagetext" => "hello there,"
]

Codes

My function

public function sendemailtoadmin(Request $request){

        $this->validate($request, array(
        'name' => 'required|max:255',
        'email' => 'required|email',
        'issue' => 'required',
        'budget' => 'nullable|numeric',
        'messagetext' => 'required|min:10|max:15000|string',
        'subject' => 'required',
      ));

      $data = array(
        'name' => $request->name,
        'email' => $request->email,
        'subject' => $request->subject,
        'issue' => $request->issue,
        'budget' => $request->budget,
        'messagetext' => $request->messagetext,
      );

      Mail::send(new ContactForm(), $data, function($message) use ($data) {
        $message->from($data['email']);
        $message->to('xxxx@xxxx.com');
        $message->subject($data['subject']);
      });

      Session::flash('flash_message', 'Your Email was sent. We will contact you shortly.');
      return redirect()->back();
    }

My email template

@component('mail::message')

<p>
Name :{{ $name}}<br>
Email address : {{ $email }}<br>
Type of issue: {{ $issue}}<br>
Subject : {{ $subject }}<br>
Budget : {{ $budget }}<br>
Message : {{ $messagetext}}
</p>


Thanks,<br>
{{ config('app.name') }}
@endcomponent

Any idea?

There should be {{ $data['name'] }}, instead of {{ $name }}, in the email template.
The same applies for all the variables, $email, $issue, ..., in the template.

SOLVED

I have changed new ContactForm() to 'my.view.address' and used HTML view instead of markdown.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM