I have a controller
public function contactsform()
{
$this ->validate(request(), ['name'=>'required','phone'=>'required','email'=>'required','text'=>'required','file'=>'required']);
$message = "Имя: ".request('name')."\nE-mail:".request('email')."\nPhone:" .request('phone')."\nFile:" .request('file');
$subject = "Форма с сайта iten.kz";
$headers = 'From: info@iten.kz' . "\r\n" .'Reply-To: info@iten.kz' . "\r\n".'X-Mailer: PHP/' . phpversion();
mail('015@i-marketing.kz', $subject, $message, $headers);
return view('ru.page.contacts');
}
and my blade form
<form action="/contactsform" method="POST" enctype="multipart/form-data">
@csrf
<div class="order_form flex">
<div class="flex input_block">
<input type="text" name="name" class="order_input" placeholder="Имя*" required="">
<input type="text" class="order_input" id="phone2" name="phone" placeholder="Телефон*" maxlength="20" required="">
<input type="text" class="order_input" name="email" placeholder="E-mail" maxlength="20" required="">
</div>
<div class="form_send">
<textarea placeholder="Задайте вопрос" name="text"></textarea>
<div class="flex add_block">
<div class="add add_file"><input type="file" value="Прикрепить файл" name="file"></div>
<div class="add add_txt"><span>Вы можете прикрепить файл заявке до 10 мб</span></div>
</div>
<div class="form_send_btn"><button type="submit" class="sub">Оставить заявку</button></div>
</div>
</div>
</form>
I want to send input type file email but I don't know. Please help me to figure out how to send an email with an attachment.
If you are working with Laravel, do not use mail
function to send mail. Laravel provides you with a possibility to use OOP power.
Generate mailable class using:
php artisan make:mail SendFormFromWebsite
To attach file, just call ->attach()
method.
Full documentation could be found here
PS Do not send emails from the Controller. It should be stored and processed with a queue.
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.