PHP电子邮件表单在完成后显示确认页面,但是,它不会将电子邮件发送到指定的电子邮件地址

时间:2016-05-04 02:33:47

标签: php html forms twitter-bootstrap email

所以我在Bootstrap模式中有一个HTML表单,我想发送到我的电子邮件。我的HTML表单指向“php”文件夹中名为“send_form_email.php”的PHP文件,但是,一旦我在表单中单击“提交”,它会将我重定向到成功页面,但电子邮件不会出现在我的电子邮件。我已经检查过多次确认电子邮件地址是正确的,甚至使用了不同的电子邮件地址,我每次都检查了我的垃圾邮件文件夹,但它也没有。以下是我的代码:

HTML:

<form action="php/send_form_email.php" method="post">
     First Name: <input type="text" name="first_name" required><br>
     Last Name: <input type="text" name="last_name" required><br>
     Email: <input type="text" name="email" required><br>
     Message:<br>
     <textarea rows="5" name="message" cols="30" required></textarea>
     <br>
     <input type="submit" name="submit" value="Submit">
</form>

PHP:

<?php 
if(isset($_POST['submit'])){
    $to = "info@myemail.com"; // changed address for example purposes but put my email in here
    $from = $_POST['email']; // this is the sender's Email address
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $subject = "Form submission";
    $subject2 = "Copy of your form submission";
    $message = $first_name . " " . $last_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.";
    // You can also use header('Location: thank_you.php'); to redirect to another page.
    }
?>

有关电子邮件无法发送的原因的任何想法?

0 个答案:

没有答案