P
P
PRIZRAKeee2017-10-27 14:21:30
PHP
PRIZRAKeee, 2017-10-27 14:21:30

How to send form attachment to email without uploading file to phpmailer server?

There is a vacancy form on the site. It is necessary that after the user selects a file and presses the "send" button, the letter along with the file goes immediately to the mail. I managed to collect data from the form and send it to the mail, but it doesn’t work with the file. I could only find examples of how to send a file from the server to the mail, but I need the file to leave the form immediately to the mailbox. Help me please.
Form html code

<form method="post" class="sform send_resume_form resume_class" enctype="multipart/form-data">
                        <fieldset>
                            <div class="label">
                                <label for="call_order_name">Ваше имя*</label>
                            </div>
                            <input class="textbox required required_clean" type="text" name="name_form" data-div="form_item_name">
                        </fieldset>
                        <fieldset>
                            <div class="label">
                                <label for="call_order_phone">Ваш телефон*</label>
                            </div>
                            <input class="required phone phonebox required_clean" type="text" name="phone_form" data-div="form_item_phone">
                        </fieldset>
                        <fieldset>
                            <div class="label">
                                <label>Комментарий</label>
                            </div>
                            <textarea class="required_clean" rows="5" cols="27" name="message_form" data-div="form_item_message"></textarea>
                        </fieldset>
                        <fieldset>
                            <input name="file_form" type="file" id="filea">
                        </fieldset>
                        

                        <fieldset class="submit-wrap">
                       <input type="button" class="submit class_resume_form" value="Отправить" data-div="send_resume_form" data-title="send_resume_form_title" data-closeform="send_resume_form_close">
                      </fieldset>
                    </form>

PHP script code
<?php
$title = $_POST['title'];
$name = $_POST['name_form'];
$phone = $_POST['phone_form'];
$message = $_POST['message_form'];
$filea = $_POST['file_form'];

$to = "Тут почта";
require("lib/class.phpmailer.php");

// На всякий случай указываем настройки
// для дополнительного (внешнего) SMTP сервера.
$site['smtp_mode'] = 'disabled'; // enabled or disabled (включен или выключен)
$site['smtp_host'] = null;
$site['smtp_port'] = null;
$site['smtp_username'] = null;

class FreakMailer extends PHPMailer
{
    var $priority = 3;
    var $to_name;
    var $to_email;
    var $From = null;
    var $FromName = null;
    var $Sender = null;

}

// инициализируем класс
$mailer = new FreakMailer();

// Устанавливаем тему письма
$mailer->Subject = $title;

/// Задаем тело письма
$mailer->Body =  "Сообщение пришло с формы $title\nНаписал(а): $name\nНомер телефона: $phone\nКомментарий: $message,";

// Добавляем адрес в список получателей
$mailer->AddAddress('Моя почта', 'Моя почта');


if(!$mailer->Send())
{
  echo 'Не могу отослать письмо!';
}
else
{
  echo 'Письмо отослано!';
}
$mailer->ClearAddresses();
$mailer->ClearAttachments();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2017-10-27
@PRIZRAKeeee

so that the file leaves the form immediately to the mailbox

No. Only through uploading to the server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question