简体   繁体   中英

My contact HTML page redirects to my contact PHP and doesn't send email

I'm trying to get my contact form to work. When I fill out the form and click "send" it redirects to the contact.php and doesn't send email or work. Can anyone help me and explain what's wrong with my code? This is the code below:

<div id="zContact_form">                        
    <center><?php echo $text;?></center>                    
    <strong>We will reply within 15 minutes, that's a Promise!!.    </strong>
    <form name="form1" id="ff" method="post"     action="contact.php">
        <label>
            Name*:
            <input type="text" placeholder="Please enter your name"     name="name" id="name" required>
        </label>

        <label>
            Email*:
            <input type="email" placeholder="info@youbelizetours.com" name="email" id="email" required>
        </label>

        <label>
            Message*:
            <textarea name="message" id="message">Please enter your message</textarea>
        </label>

        <input class="sendButton" type="submit" name="Submit" value="Send">      
    </form>

<?php
    $text = "<span style='color:red; font-size: 35px; line-height: 40px; magin: 10px;'>Error! Please try again.</span>";

    if(isset($_POST['name'])){
        $name=$_POST['name'];
        $email=$_POST['email'];
        $message=$_POST['message'];
        $to = "youbelizetours@gmail.com";
        $subject = "Tour Reservations from Edwin's Adventure Tours";
        $message = " Name: " . $name ."\r\n Email: " . $email . "\r\n Message:\r\n" . $message;
        $from = "$name";
        $headers = "From:" . $from . "\r\n";
        $headers .= "Content-type: text/plain; charset=UTF-8" . "\r\n"; 

        if(mail($to,$subject,$message,$headers)){
            $text = "<span style='color:blue; font-size: 35px; line-height: 40px; margin: 10px;'>Your Message was sent successfully !</span>";
        }
    }
?>

Is there anything wrong with the code? or may it be something else I'm not seeing.

What i can see is missing closing bracket for $_POST in the last. rest code seems fine to me provided contact.php is separate file or entire code is in contact.php. I tested the code using form action=""

<?php
$text = "<span style='color:red; font-size: 35px; line-height: 40px; magin: 10px;'>Error! Please try again.</span>";

if(isset($_POST['name']))
{
    var_dump($_POST);
    $name=$_POST['name'];
    $email=$_POST['email'];
    $message=$_POST['message'];

    $to = "youbelizetours@gmail.com";
    $subject = "Tour Reservations from Edwin's Adventure Tours";
    $message = " Name: " . $name ."\r\n Email: " . $email . "\r\n Message:\r\n" . $message;

    $from = "$name";
    $headers = "From:" . $from . "\r\n";
    $headers .= "Content-type: text/plain; charset=UTF-8" . "\r\n"; 

    if(mail($to,$subject,$message,$headers))
    {
      $text = "<span style='color:blue; font-size: 35px; line-height: 40px; margin: 10px;'>Your Message was sent successfully !</span>";
    }
}
?>
<div id="zContact_form">            
    <center><?php echo $text;?></center>
    <strong>We will reply within 15 minutes, that's a Promise!!.</strong>

    <form name="form1" id="ff" method="post" action="">
    <label>
    Name*:
    <input type="text" placeholder="Please enter your name" name="name" id="name" required>
    </label>

    <label>
    Email*:
    <input type="email" placeholder="info@youbelizetours.com" name="email" id="email" required>
    </label>

    <label>
    Message*:
    <textarea name="message" id="message">Please enter your message</textarea>
    </label>
    <input class="sendButton" type="submit" name="Submit" value="Send">
    </form>
</div>  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM