将文件附加到联系表单上的电子邮件

时间:2017-05-30 21:13:58

标签: php forms laravel-5.3 octobercms

我正在尝试创建一个联系表单组件,将文件附加到联系表单并将表单作为电子邮件发送而不将文件保存到服务器我的default.htm是

<form data-request="onSend" data-request-success="alert('We have recieved your email.. we\'ll get back to you shortly'); this.reset();" data-request-error="alert(jqXHR.responseText);" class="col s12">
  <input type="text" class="validate" id="first_name" name="first_name">
  <label for="first_name" class="active">First Name</label>
  <input type="text" id="last_name" name="last_name">
  <label for="last_name">Last Name</label>
  <input type="email" class="validate" id="email" name="email">
  <label data-success="right" data-error="wrong" for="email">Email</label>
  <textarea id="textarea1" name="textarea1" class="materialize-textarea"></textarea>
  <label for="textarea1">Description</label>
  <select multiple name="value[]">
    <option value="" disabled selected>Choose your option</option>
    <option value="1">One</option>
    <option value="2">two</option>
    <option value="3">three</option>
  </select>
  <label>Choose Option</label>
      <span>File</span>
      <input name="resume" type="file">
      <input class="file-path validate" type="text" placeholder="Upload one or more files">
  <label for="datepicker">Set the Date</label>
  <input type="date" class="datepicker" id="datepicker" name="datepicker">
  <input type="checkbox" class="filled-in" id="filled-in-box" checked="checked" />
  <label for="filled-in-box">Send copy to my email</label>
  <button class="btn-large waves-effect waves-light" type="submit" name="action">Submit<i class="material-icons right">send</i></button>

我的ContactForm.php有

    <?php namespace Pft\Contact\Components;

 use Cms\Classes\ComponentBase;
 use Input;
 use Mail;
 use Validator;
 use Redirect;
 use ValidationException;

 class ContactForm extends ComponentBase
 {
    /**
      * Returns information about this component, including name and description.
      */
     public function componentDetails()
     {
         return
         [
            'name' => 'Contact Form',
            'description' => 'A Contact form for Laratify Octaskin theme'
         ];
     }
     function onSend()
     {
        $data = post();
        $rules = 
         [
             'first_name' => 'required|min:5',
             'last_name' => 'required|min:3',
             'email' => 'required|email|unique:users',
             'textarea1' => 'required'
         ];      
        $validator = Validator::make($data, $rules);        
         if ($validator->fails()){
                // do something
             throw new ValidationException($validator);
         }else {
             // These variables are available inside the message as Twig
             $vars = [
                        'first_name' =>  Input::get('first_name'),
                        'last_name' => Input::get('last_name'),
                        'email' => Input::get('email'),
                        'textarea1' =>  Input::get('textarea1'),
                        'datepicker' =>  Input::get('datepicker'),
                        'value' =>  Input::get('value'),    
                        'resume' =>  Input::get('resume'),                      
                    ];          
             Mail::send('yourappname.website::mail.contactform', $vars, function ($message)  {
                $message->to('youremail', ' Admin Person');
                $message->subject('New Contact');
                $message->attach( Input::file('resume') );
             });
         }
     }
 }

但是我得到并且错误地说“路径不能为空”我不知道什么路径因为我不希望将文件保存到服务器

0 个答案:

没有答案