PHP почтовый код не работает - PullRequest
0 голосов
/ 11 мая 2018

Это мой текущий код. Почему это не работает? Он отправляет почту, но в разделе $message он не извлекает из $name, $phone или $email. Кроме того, в самом письме $from не работает. Единственное, что работает правильно - это $to и $subject.

<?php 
if(isset($_POST['submit'])){
$to = "emailgoeshere@example.com";
$from = $_POST['email']; 
$name = $_POST['name'];
$subject = "Form submission";
$phone = $_POST['phone'];
$email = $_POST['email'];
$message = $name . " " . $phone . " has the email:" . "\n\n" . $_POST['email'];

$headers = "From: <".$from. ">" ;
mail($to,$subject,$message,$headers);
echo "We have Recieved your Enquiry, We will get back to you soon. We Appreciate Your Patient Thank You.";
}
?>


<div class="right-wrapper">
                <div class="contact-form">
                    <p class="contact-form-info">Leave your contact info below, and we'll contact you shortly:</p>
                    <form action="https://www.forevrmarketing.com/webdesigndemo/eddy1155/functions/send-mail.php" method="post">
                    <input type="text" placeholder="Name" class="name" name="name" id="name">
                    <input type="email" placeholder="Email" class="email" class="email" id="email">
                    <input type="number" placeholder="Phone" id="phone" class="phone" class="phone" oninput="this.value=this.value.replace(/[^\d]/,'')" maxlength="15">
                    <input class="submit" type="submit" name="submit" value="Submit">

                    <div class="loader" disabled><i class="fa fa-spin fa-spinner" aria-hidden="true"></i></div>
                    <p class="form-details form-era">Call us at <strong style="font-weight: 600">+65 9691 1155</strong> Or <br><span class="wts"><img src="img/icon.png" alt="WhatsApp Icon"></span> <strong style="font-weight: 600">Whatsapp</strong> us</p>
                    <p class="reponse"></p>
                </div>
            </div>

1 Ответ

0 голосов
/ 11 мая 2018

В двух полях вашей формы отсутствуют атрибуты name, поэтому на них нельзя ссылаться как $_POST['email'] и $_POST['phone'].

<input type="email" placeholder="Email" class="email" class="email" id="email">
<input type="number" placeholder="Phone" id="phone" class="phone" class="phone" oninput="this.value=this.value.replace(/[^\d]/,'')" maxlength="15">

должно быть

<input type="email" placeholder="Email" name="email" class="email" id="email">
<input type="number" placeholder="Phone" id="phone" name="phone" class="phone" oninput="this.value=this.value.replace(/[^\d]/,'')" maxlength="15">

Это должно решить, что $from, $phone и $email будут пустыми.

Кроме того, в вашей строке $message вы можете заменить $_POST['email'] на $email.

Наконец, добавьте закрывающий </form> к вашему коду.

...