@SavchenkoD

Как сделать обратную форму активной?

Есть сайт www.your-coffee.in.ua (не реклама, он не готов)
На нём есть формы отправки: "Email, телефон, имя".
Как сделать так чтобы мне приходили введенные данные на почту?

Если можно объясните популярно. Для новичка.

Безмерно благодарен!!!
  • Вопрос задан
  • 440 просмотров
Решения вопроса 1
space2pacman
@space2pacman Куратор тега CSS
Просто царь.
<?php 
if(isset($_POST['submit'])){
    $to = "email@example.com"; // this is your Email address
    $from = $_POST['email']; // this is the sender's Email address
    $first_name = $_POST['first_name'];
    $subject = "Form submission";
    $subject2 = "Copy of your form submission";
    $message = $first_name . " wrote the following:" . "\n\n" . $_POST['message'];
    $message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];

    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$subject,$message,$headers);
    mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
    echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
    }
?>


<form action="" method="post">
Ваше имя <input type="text" name="first_name"><br>
Email: <input type="text" name="email"><br>
Телефон:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input type="submit" name="submit" value="Submit">
</form>


Вот эту форму замени на ту, которая сейчас на сайте
<form action="" method="post">
						<li>
							<input name="first_name" type="text" class="text" value="Ваше имя" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Ваше имя';}">
							<a class="name" href="#"></a>
						</li>
						<li>
							<input name="email" type="text" class="text" value="Email Адресс" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Email Адресс';}">
							<a class="mail" href="#"></a>
						</li>
						<li>
							<input name="message" type="text" class="text" value="Телефон" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Телефон';}">
							<a class="num" href="#"></a>
						</li>
							<input type="submit" value="Заказать звонок">
					</form>
Ответ написан
Пригласить эксперта
Ответы на вопрос 2
@tommy_13
написать обработчик, который будет отправлять введенные данные. Например, на php
Ответ написан
Комментировать
lazalu68
@lazalu68
Salmon
Ого, пакмэн уже выложил код. Но всё же дам еще один пример кода, мой просто украден в интернетах)

mail.php
<?php

/* attributes check */

if (!isset($_POST['some_attribute']) || empty($_POST['some_other_attribute'])) {
	echo 'false';
	exit();
}

/* attributes bindings */

$some_attribute = htmlspecialchars($_POST['some_attribute']);
$some_other_attribute = htmlspecialchars($_POST['some_other_attribute']);

/* quality attribute check */

if (strlen($some_attribute) > 10 || strlen($some_other_attribute) > 120) {
	echo 'false';
	exit();
}

$email = 'test@test.com'

$title = '=?utf8?b?' . base64_encode('some title') . '?=';

$ip = $_SERVER["REMOTE_ADDR"];

/* some hoster (and some php versions) may support date or current_time */

$date = date('d.m.Y H:i:s'); 
//$date = current_time('d.m.Y H:i:s', 0);

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .= 'From: from somewhere <'.$email.'>' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();

$html = '<p>Hello! It is a sample email, enjoy!</p>';

if(mail($email, $title, $html, $headers)) {
	echo 'true';
} else {
	echo 'false';
}

Ответ написан
Ваш ответ на вопрос

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

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