Answer the question
In order to leave comments, you need to log in
Why is the file not being sent by mail?
Hello. Please help. The site has a form for vacancies. All fields work. It was required to send a text file with a resume. It seems that everything was done correctly, but when sending data from the form (if we uploaded a file), an error appears. Without downloading the file, everything works. Console error "Swift_IoException in FileByteStream.php line 144: Unable to open file for reading".The file is stored in a temporary folder and is not saved after sending (this is what I need). I tried to upload the file to the server and, when sending mail, manually enter the path to the file for attach("/server folders/tmp/php/uploads/phpfoeu5Y/resume.docx"), then the file is attached and comes to the mail. But if I put the same path into the variable $path = "/server folders/tmp/php/uploads/phpfoeu5Y/resume.docx"; and output attach($path) then it will give me an error. Please help me point out my mistake.
<form action="/ajax/vacancy" class="pop_form" id="form-resume" enctype="multipart/form-data" data-id="vacancy" onsubmit="sendVacancy(this, event)">
<div class="f_tit">Отклик на вакансию</div>
<div class="row_form_information_vacancy">
<div class="form_information_vacancy">
<input type="text" name="name_vacancy" value="" class="form_information_vacancy_name" readonly>
<input type="text" name="wages" value="" class="form_information_vacancy_wages" readonly>
</div>
</div>
<input type="file" name="ypicture" id="ypicture" value="" style="display:none;">
<fieldset class="form_block_vacancy">
<label>
<input type="text" name="name" value="" placeholder="Имя, фамилия" class="f_field form_input_vacancy_name">
</label>
</fieldset>
<fieldset class="form_block_vacancy">
<label>
<input type="text" name="phone" value="" placeholder="Телефон" class="f_field form_input_vacancy_phone">
</label>
</fieldset>
<fieldset class="form_block_vacancy">
<label>
<input type="text" name="email" value="" placeholder="E-mail:" class="f_field form_input_vacancy_mail">
</label>
</fieldset>
<fieldset class="form_block_vacancy">
<label>
<textarea name="text" cols="30" rows="5" placeholder="Комментарий:" class="f_ta form_textarea_vacancy"></textarea>
</label>
</fieldset>
<div class="attach-file-wrap" style="display:none;">
<label class="text attach-file" for="file">
<img src="/images/resume.png">
<div class="fileLabel">Прикрепите файл формата doc, docx или pdf размером не более 10 Мб</div>
<div class="fileLabel2 hide"></div>
</label>
<input class="text attach-file-input file" type="file" name="file">
</div>
<div class="policy policy_form_vacancy">Нажимая кнопку «Отправить», вы подтверждаете свое согласие на обработку <a href="/policy" target="_blank" style="color: #000">персональных данных</a></div>
<input type="submit" name="" value="Отправить" class="f_btn">
</form>
function sendAjaxResume(t,e,i,n){
e=e||{},"undefined"==typeof n&&(n="json");
var formData = new FormData($('#form-resume')[0]);
$.ajax({
url:t,
data: formData,
dataType:n,
processData: false,
contentType: false,
type:"post",
dataType: 'json',
beforeSend:function(t){
return t.setRequestHeader("X-CSRF-Token",$("meta[name='csrf-token']").attr("content"))
},
success:function(t){
"function"==typeof i&&i(t)
},
error:function(t,e,i){
alert("Не удалось выполнить запрос! Ошибка на сервере.");
}
})
}
function sendVacancy(t,e,id,site){
e.preventDefault(),t=$(t);
var i=t.serialize(),n=$(t).attr("action");
t.find(".err-msg-block").remove();
sendAjaxResume(n,i,function(e)
{
if("undefined"!=typeof e.errors)
{
applyFormValidate(t,e.errors);
var i=[];
for(var n in e.errors)i.push(e.errors[n]);
var o=i.join("<br />");
t.find(".f_tit").after('<div class="err-msg-block">'+o+"</div>")
} else {
resetForm(t),popup("Спасибо за письмо, в ближайшее время мы Вам ответим!");
}
})
}
public function postVacancy() {
$data = Request::only(['name', 'phone','email','text','name_vacancy','wages']);
$valid = Validator::make($data, [
'name' => 'required',
'phone' => 'required',
'email' => 'required',
], [
'name.required' => 'Не заполнено поле Имя',
'phone.required' => 'Не заполнено поле Телефон',
'email.required' => 'Не заполнено поле e-mail',
]);
if ($valid->fails()) {
return ['errors' => $valid->messages()];
} else {
$path = $_FILES["file"]["tmp_name"].'/'.$_FILES["file"]["name"];
$feedback_data = [
'type' => 10,
'data' => $data
];
$feedback = Feedback::create($feedback_data);
Mail::queue('mail.callback', ['feedback' => $feedback], function ($message) use ($feedback) {
$title = $feedback->id . ' | Вакансия | ';
$message->from($this->fromMail, $this->fromName)
->to(Settings::get('feedback_email'))
->subject($title);
$message->attach($path);
});
return ['success' => true];
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question