Answer the question
In order to leave comments, you need to log in
How to make a PHP autoresponder to a client's mail?
1. Essence: It is necessary that after submitting the form with the E-mail field, the person who fills in will receive a response from the site administrator with the price list attached to the letter to his specified E-Mail. Is it feasible at all?
2. There is a last resort: set up an autoresponder on the admin mail, but there you can’t attach a price list and there is a problem, the letter from the application does not come from the specified E-Mail of the client.
If you don’t tell me with the first, at least help with the second. How to make the letter to the admin come from the E-Mail, which was specified in the form
Form
<form>
<input type="hidden" name="project_name" value="Название сайта">
<input type="hidden" name="form_subject" value="Запрос прайс-листа">
<input type="text" name="E-mail" placeholder="Введите E-mail" required><br>
<p>На эту почту мы отправим прайс-лист</p>
<input type="text" name="Phone" placeholder="Введите номер телефона"><br>
<p>Убедимcя, что Вы получили прайс</p>
<button>Жду прайс-лист</button>
</form>
<?php
$method = $_SERVER['REQUEST_METHOD'];
//Script Foreach
$c = true;
if ( $method === 'POST' ) {
$project_name = trim($_POST["project_name"]);
$admin_email = "[email protected]";
$form_subject = trim($_POST["form_subject"]);
$from_mail = trim($_POST["E-mail"]);
foreach ( $_POST as $key => $value ) {
if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
$message .= "
" . ( ($c = !$c) ? '<tr>':'<tr style="background-color: #f8f8f8;">' ) . "
<td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td>
<td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td>
</tr>
";
}
}
} else if ( $method === 'GET' ) {
$project_name = trim($_GET["project_name"]);
$admin_email = trim($_GET["admin_email"]);
$form_subject = trim($_GET["form_subject"]);
foreach ( $_GET as $key => $value ) {
if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
$message .= "
" . ( ($c = !$c) ? '<tr>':'<tr style="background-color: #f8f8f8;">' ) . "
<td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td>
<td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td>
</tr>
";
}
}
}
$message = "<table style='width: 100%;'>$message</table>";
function adopt($text) {
return '=?UTF-8?B?'.base64_encode($text).'?=';
}
$headers = "MIME-Version: 1.0" . PHP_EOL .
"Content-Type: text/html; charset=utf-8" . PHP_EOL .
'From: '.adopt($project_name).' <'.$from_mail.'>' . PHP_EOL .
'Reply-To: '.$admin_email.'' . PHP_EOL;
mail($admin_email, adopt($form_subject), $message, $headers );
Answer the question
In order to leave comments, you need to log in
There are two ways to solve the problem.
1) Make a file attachment directly in the feedback form handler
2) Make a cron task that will scan the mailbox, parse letters and respond to them.
It's easier to do the first one. Take composer and any library for working with soap, for example swiftmailer
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question