表格上的if-echo-else语法错误?

时间:2015-06-23 20:34:59

标签: php forms

我无法获得php联系表单。所有字段均已填写完整,并且已提交'我总是得到其他的'声明(发送邮件时出错)。我对PHP知之甚少,所以我想知道if-echo-else行是否存在语法错误?

这是php代码:

<?  
if($_POST['email']!='')
{
    $emailto="dgm102@hotmail.co.uk"; // change in this line
    $subject2="Contact Request";            
    $to2=$emailto;
    $mailcontent2="<html>
    <head>
    </head>
    <body>
    <table width='800' border='0' cellspacing='2' cellpadding='0'>
      <tr>
        <td align='left'>
            <p>Hi,</p>
                  <strong style='color:#C59800'>New Contact Request has been sent with the below details.</strong><br /><br />
                  <strong>Name: </strong>".stripslashes($_POST['name'])."<br />
                  <strong>Email: </strong>".stripslashes($_POST['email'])."<br />
                  <strong>Message: </strong>".nl2br(stripslashes($_POST['message']))."<br />
            <p>Thanks</p>
        </td>
      </tr>
    </table>
    </body>
    </html>
    ";
    //echo $to2;echo $subject2;echo $mailcontent2;
    if($_SERVER['HTTP_HOST']!="yogs")
    {
        $headers2  = "MIME-Version: 1.0" . "\r\n";
        $headers2 .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
        $headers2 .= "Reply-To: ".$_POST["email"]."\r\n";
        $headers2 .= "From: ".stripslashes($_POST['email'])." <".stripslashes($_POST['email']).">" . "\r\n";    
        if(mail($to2,$subject2,$mailcontent2,$headers2))
        {
            echo "<script type='text/javascript'>window.location.href='thanks.html';</script>";
            exit;   
        }
        else
        {
            echo "Error sending email!";
        }
    }   
}
else
{
    echo "Please enter email address";
}   
?>

和html

<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<title>Shirley Fire Department</title>
<link href='http://fonts.googleapis.com/css?family=Tinos:700' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=PT+Serif:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="contact/contact.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale-1.0">
<link rel="icon" href="favicon.ico" type="image/ico" />
<link rel="shortcut icon" href="favicon.ico.png" />
</head>    

<body class="body">
<header class="mainheader">
    <img src="img/new-banner-small.JPG">
    <div class="header-flex">
    <h1>Shirley Volunteer Fire Department</h1>
    <div id="nav">
     <div id="nav_wrapper">
    <div id="drop-down-display"> <!-- ===DISPLAYS DROPDOWN MENU OVER CONTENT=== -->
    <ul>
    <li><a href="index.html">HOME</a></li>
    <li><a href="department.html">DEPARTMENT<img src="img/dropdown-arrow.png"></a>
        <ul>
        <li><a href="department-meet-our-team.html">Active Members</a></li>
        <li><a href="apparatus.html">Apparatus</a></li>
        <li><a href="department-photo-gallery.html">Photo Gallery</a></li>
        </ul>
    <li><a href="regs2.html">REGULATIONS</a></li>
    <li><a href="contact.html">CONTACT</a></li>
      </ul> </div>
        </div>
    </div>
    </div>
</header>
<!-- ===START MAIN=== -->
<div class="main-container">
    <div class="main">
        <h2>Contact</h2>
        <article>
        <p><span style="color:red"><strong>In case of emergency, call 911</strong></span></p>
            <p>The Shirley Fire Department is located at:<br />
                <strong>2795B Sheringham Point Road<br />
                Shirley V9Z 1G4<br />  
                    British Columbia</strong></p>
            <p>Phone (non-emergencies only): 250-646-2107</p>   
            <p>Click <a href="https://www.google.com/maps/place/Shirley,+BC+V0S,+Canad%C3%A0/@48.3892994,-123.9032574,18z/data=!4m2!3m1!1s0x548f1bdc9ed6e3f7:0xcb47852af628b51a">here</a> to view a map of our location.</p>
            <p>You are welcome to visit us at the fire hall on Thursdays just before 7pm. Alternatively, fill in the contact form below and we will get in touch soon.</p></article>
<!-- ===FORM=== -->
<form method="post" action="sendmail.php" enctype="multipart/form-data" name="frmcontact" id="frmcontact">
<!-- ===START FIELDS=== -->
<div class="fieldset">
<h2 class="contact-form">Contact Us</h2>
<div class="fields">
<p class="row">
<label>Name:</label>
<input type="text" id="first-name" name="name" class="field-large" required="required" aria-required="true" /></p>   
<p class="row"><label>Email<span class="required">*</span>:</label><input type="email" required="required" aria-required="true" id="email" name="email" placeholder="yourname@example.com" class="field-large" /></p>   
<p class="row"><label>Message:</label><textarea id="message" id="message" name="message" cols="40" rows="5" class="field-large"/></textarea></p>
<input type="submit" value="submit" class="btn" />
</div>
</div>
</form>
        </div>
<!-- ===START ASIDE=== -->
<div class="aside-flex">
    <div id="aside-flex-img">
        <aside class="call-911">
        <img src="img/call911.png" alt="call911"/>
            </aside>
    <div id="aside-flex-volunteers">
        <aside class="volunteers">
<h2>VOLUNTEER FIREFIGHTERS NEEDED</h2>
<p>For more information <br>
    contact Chief <a href= "contact.html">Marty Gilbertson</a></p>
            </aside>
        </div>  
    </div>   
</div>
</div>
<!-- ===START FOOTER=== -->    
<footer class="mainfooter">
<p><small>Shirley Volunteer Fire Department. All Rights Reserved. Copyright 2015.</small></p>
</footer>
</body>
</html>

这是相关网页的实时链接: Contact form

0 个答案:

没有答案