@maxguselnik

Как в этой форме добавить отправку письма клиенту, и возможно ли это?

Вот php
spoiler
<?php

    require('config.php');
    
    $name = htmlspecialchars(stripslashes(trim($_POST['form_name'])));
	$phone = htmlspecialchars(stripslashes(trim($_POST['form_phone'])));
	$email = htmlspecialchars(stripslashes(trim($_POST['form_email'])));
    $date = htmlspecialchars(stripslashes(trim($_POST['form_date'])));
    $time = htmlspecialchars(stripslashes(trim($_POST['form_time'])));
    $work = htmlspecialchars(stripslashes(trim($_POST['form_work'])));
	$message = htmlspecialchars(stripslashes(trim($_POST['form_message'])));
    $subject = "Создана заявка с ".$_SERVER['HTTP_REFERER'];
    
    $text = '';
    $text .= (!empty($name))?'<p><strong>Имя:</strong> '.$name.'</p>':'';
    $text .= (!empty($phone))?'<p><strong>Телефон:</strong> '.$phone.'</p>':'';
	$text .= (!empty($email))?'<p><strong>email:</strong> '.$email.'</p>':'';
    $text .= (!empty($date))?'<p><strong>Дата:</strong> '.$date.'</p>':'';
    $text .= (!empty($time))?'<p><strong>Время:</strong> '.$time.'</p>':'';
    $text .= (!empty($work))?'<p><strong>Услуга:</strong> '.$work.'</p>':'';
	$text .= (!empty($message))?'<p><strong>Сообщение:</strong> '.$message.'</p>':'';
    $text .= (!empty($_SERVER['HTTP_REFERER']))?'<p><strong>url:</strong> '.$_SERVER['HTTP_REFERER'].'</p>':'';
    
    $headers = '';
    $headers .= "From: " . $from . "\r\n";
    $headers .= "MIME-Version: 1.0 \r\n";
    $headers .= "Content-Type: multipart/mixed; boundary=$boundary; charset=utf-8\r\n\r\n";
    
    $msg = "--$boundary\r\n";
    $msg .= "Content-Type: text/html; charset=utf-8\r\n";
    $msg .= "Content-Transfer-Encoding: base64\r\n\r\n";
    $msg .= chunk_split(base64_encode($text));

	if(!empty($_FILES['files'])){
        $sizes = 0;
		foreach($_FILES['files']['name'] as $key => $val){
            $name = $_FILES['files']['name'][$key];
            $name = str_replace(' ', '_', $name);
            if($name == '') continue;
            $type = $_FILES['files']['type'][$key];
            $tmp_name = $_FILES['files']['tmp_name'][$key];
            $error = $_FILES['files']['error'][$key];
            $size = $_FILES['files']['size'][$key];

            if($error > 0){
                echo 'Произошла ошибка при загрузке файла "'.$name.'"';
				exit;
            }

			$ext = strtolower(substr($name, strpos($name,'.'), strlen($name)-1));
			if(!in_array($ext, $extensions)){
				echo 'Тип файла "'.$name.'" запрещен к загрузке';
				exit;
			}

			$sizes += $size;
			if($sizes > $maxSize){
				echo 'Суммарный объем файлов превышает 10Мб';
				exit;
			}
            $content = file_get_contents($tmp_name);
            $encoded_content = chunk_split(base64_encode($content));

            //attachment
            $msg .= "--$boundary\r\n";
            $msg .="Content-Type: $file_type; name=".$name."\r\n";
            $msg .="Content-Disposition: attachment; filename=".$name."\r\n";
            $msg .="Content-Transfer-Encoding: base64\r\n";
            $msg .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n";
            $msg .= $encoded_content;
		}
	}

    $result = mail($to, $subject, $msg, $headers);
	
	if($result){
		echo "Спасибо! Ваша заявка отправлена";
		} else {
		echo "Ваша заявка не отправлена! Попробуйте еще раз";
	}

?>
  • Вопрос задан
  • 91 просмотр
Пригласить эксперта
Ответы на вопрос 1
@kifirch
А вот эта строчка кому письмо отправляет?
$result = mail($to, $subject, $msg, $headers);
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы