Отправка письма с одним файлом:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
if(isset($_POST['oz'])){
  if(($_POST['fio']!='') && ($_POST['phone']!='') && ($_POST['mail']!='')){
  if(count($_FILES['file']['name']!=0)){
  $path = $_FILES['file']['name'];
  copy($_FILES['file']['tmp_name'],"upload/file/".$path);
}
$to = email@email.ru;
$filename = $_FILES['file']['name']; //Имя файла для прикрепления
$message = '<strong>ФИО:</strong> '.$_POST['fio']."<br/>";
$message .= '<strong>Телефон:</strong> '.$_POST['phone']."<br/>";
$message .= '<strong>E-mail:</strong> '.$_POST['mail']."<br/>";
$message .= '<strong>Сообщение:</strong> '.$_POST['mess'];
$subject = "Заявка онлайн с сайта";
$from_name = $_POST['fio'];
$from_mail = $_POST['mail'];
$bound="spravkaweb-1234";
$header="From: "$from_name" <$from_mail>\n";
$header.="To: $to\n";
$header.="Subject: $subject\n";
$header.="Mime-Version: 1.0\n";
$header.="Content-Type: multipart/mixed; boundary="$bound"";
$body="\n\n--$bound\n";
$body.="Content-type: text/html; charset="utf-8"\n";
$body.="Content-Transfer-Encoding: quoted-printable\n\n";
$body.="$message";
$f = 'upload/file/'.$_FILES['file']['name'];
$file=fopen($f,"rb");
$body.="\n\n--$bound\n";
$body.="Content-Type: application/octet-stream;";
$body.="name="".basename($_FILES['file']['name']).""\n";
$body.="Content-Transfer-Encoding:base64\n";
$body.="Content-Disposition:attachment\n\n";
$body.= base64_encode(fread($file,filesize($f)))."\n";
$body.="$bound--\n\n";
mail($to, $subject, $body, $header);
}

отправка почты с несколькими файлами:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
if((isset($_POST['sent']))&&(count($_FILES['upl']['name']!=0))){
if(($_POST['fio']!='') && ($_POST['phone']!='') && ($_POST['my_mail']!='') && ($_POST['model_car']!='')  && ($_POST['mess']!='')){
for($a=0;$a<=count($_FILES['upl']['name']);$a++) {
   $path = $_FILES['upl']['name'][$a];
   copy($_FILES['upl']['tmp_name'][$a],"uploads/".$path);
}
$to = 'pochta@pochta.com';
$filename = $_FILES['upl']['name']; //Имя файла для прикрепления
$message = '<strong>Модель авто:</strong> '.$_POST['model_car']."<br/>";
$message .= '<strong>ФИО:</strong> '.$_POST['fio']."<br/>";
$message .= '<strong>Телефон:</strong> +7'.$_POST['phone']."<br/>";
$message .= '<strong>Почта:</strong> '.$_POST['my_mail']."<br/>";
$message .= '<strong>Сообщение:</strong> '.$_POST['mess'];
$subject = "Тема";
$from_name = $_POST['fio'];
$from_mail = $_POST['my_mail'];
$bound="spravkaweb-1234";
$header="From: "$from_name" <$from_mail>\n";
$header.="To: $to\n";
$header.="Subject: $subject\n";
$header.="Mime-Version: 1.0\n";
$header.="Content-Type: multipart/mixed; boundary="$bound"";
$body="\n\n--$bound\n";
$body.="Content-type: text/html; charset="utf-8"\n";
$body.="Content-Transfer-Encoding: quoted-printable\n\n";
$body.="$message";
foreach($filename as $key => $fl){
   $f = 'uploads/'.$fl;
   $file=fopen($f,"rb");
   $body.="\n\n--$bound\n";
   $body.="Content-Type: application/octet-stream;";
   $body.="name="".basename($fl).""\n";
   $body.="Content-Transfer-Encoding:base64\n";
   $body.="Content-Disposition:attachment\n\n";
   $body.= base64_encode(fread($file,filesize($f)))."\n";
   $body.="$bound--\n\n";
}
mail($to, $subject, $body, $header);