K
K
Kirill Plotnikov2015-11-23 01:11:43
PHP
Kirill Plotnikov, 2015-11-23 01:11:43

How to send a file from a form on a website?

You need to send a file from the form that is on the site. How to implement it?
Here is the handler code:

<?php 
// несколько получателей 
$to = '[email protected]' . ', '; // обратите внимание на запятую 


// тема письма 
$subject = 'Письмо с моего сайта'; 

// текст письма 
$message = 'Вид работы: ' . $_POST['field1'] . ' Предмет:<br />' . $_POST['field2'] . '<br /> 
Файл '. $_POST['field9'] . '<br /> Название работы '. $_POST['field12'] . ' <br /> Срок сдачи: '. $_POST['field10'] . 
'<br /> Колличество страниц '. $_POST['field3'] . 
'<br /> Email '. $_POST['field7']. 
'<br /> Телефон '. $_POST['field16']. 
'<br /> Промокод '. $_POST['field13']. 
'<br /> Комментарий : '. $_POST['field11']; 

// Для отправки HTML-письма должен быть установлен заголовок Content-type 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

// Дополнительные заголовки 
$headers .= 'To: Иван <[email protected]>' . "\r\n"; // Свое имя и email 
$headers .= 'From: ' . $_POST['name'] . '<' . $_POST['email'] . '>' . "\r\n"; 


// Отправляем 
mail($to, $subject, $message, $headers); 
?>

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
SwoDs, 2015-11-23
@SwoDs

! First and most importantly, if you post something with code, use the code tag, respect those who read your post and want to help you ( joxi.ru/zANy7Gqsbbj729 )
what perversion? This is shit code, father)
And what will happen if there is only 1 email - " [email protected], " obviously a comma is superfluous.
Try using an array.
After you have collected the array, just apply implode() :
There will be no extra commas. And the code is nice and clear.
I didn’t really understand what your comment “another structure” means. Structure has nothing to do with it.
If you read what Rikcon sent you, they write that sending files via mail () is hell and it will be easier for you to use third-party solutions, for example PHPMailer .
If you are not ready to use what others have written, you can try a slightly different way - to pass a link.
Those. You can upload the file to your site, and send a download link in the letter. It's done fairly quickly. Google will help youhow to upload a php file "
ps You have so many text splices for this it is better to use the sprintf ()
function Example:

$cat = 'кот';
$dog = 'пес';
echo sprintf('%s плюс %s получится котопес', $cat, $dog);

R
Rikcon, 2015-11-23
@Rikcon

stackoverflow.com/questions/12301358/send-attachme...

P
Peter Zubkov, 2015-11-23
@peterzubkoff

It’s easier for you to make a form with 2 fields, since you don’t understand well (this is me without being aggressive).
If this is a form for ordering some freelance work, then really simplify your task to email / phone, name and comment in <textarea></textarea>.
Large long forms are needed by very large companies (eg actis.ru ) in order to quickly screen out and distribute incoming applications among managers.
In addition, the smaller the form, the greater the conversion (most often).
JaiL2Jxc0vs.jpgleadmachine.ru

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question