2017-04-18 58 views
0

我是一個使用php的完整新手。我只需要從發送到我的電子郵件地址的Web表單中獲取一些信息。我一年前編寫了這個PHP,它工作,但我現在已經回來重新使用它,它不工作。誰能幫忙?它爲一個簡單的婚禮RSVP形式。php表單不發送到電子郵件

<body> 
<center> 
<div id="logo"><img src="../content/Logo.png" width="400" height="100" /></div> 
</center> 
<div id="WebsiteContainer"> 
<center> 
<div id="Menu"> 
    <a href="home.html" >Home</a> 
    <a href="venue.html">Venue</a> 
    <a href="RSVP.php" class="loaded">RSVP</a> 
    <a href="theDay.html">The Day</a> 
    <a href="gifts.html">Gifts</a> 
</div> 
<div id="Content"> 
<p>&nbsp;</p> 
<h1><strong>RSVP</h1> 
<p> 
<center> 
<p>Please use the form below to RSVP. 
    If we don't receive an RSVP we will presume that you will not be attending. If you have any requests for our DJ, please let us know in the message box below. And should you have any particular dietary needs, please let us know these too. 
    <p> 

<?php 

// PHP creates a $_GET variable automatically which contains any URL parameters passed. We check whether the 'submit' param 
// exists using isset(), which is where our form is submitting to. If it does exist, we know the form has been submitted 
// and we can process it. 

if(isset($_GET['submit'])){ 
// Get the variables from the form 
// PHP automatically creates the $_POST variable for form data, and the keys are the names we gave the form fields 
$name = $_POST['Name']; 
$email = $_POST['Email']; 
$RSVP = $_POST['RSVP']; 
$guests = $_POST['ReplyFor']; 
$message = $_POST['message']; 

// Lets build the email body so it includes the name too 
// PHP concatenates strings with . 
$emailBody = $name . " has RSVP'd! \r\n\r\n"; 
$emailBody .= "Name: " . $name . "\r\n"; 
$emailBody .= "Email: " . $email . "\r\n"; 
$emailBody .= "Status: " . ($RSVP == 'not') ? "Not attending" : "Attending" . "\r\n"; 
$emailBody .= "Guests: " . ($guests > '1') ? "Themselves and " . ($guests - 1) . " guest(s)" : "Themselves only" . "\r\n"; 
$emailBody .= "Message: " . $message . "\r\n"; 

// Lines in emails must be under 70 characters, so we can use PHP's wordwrap() function to add line breaks 
$emailBody = wordwrap($emailBody, 70, "\r\n"); 

// Create a subject that's easy to browse in your email client 
$extraSubject = ($guests > '1') ? "(plus " . ($guests - 1) . " guest(s))" : ""; 
$subject = $name . " is " . (($RSVP == 'not') ? ' not attending' : ' ATTENDING ' . $extraSubject); 

// Send the mail using PHP's built-in mail() function 
// See http://php.net/manual/en/function.mail.php 
mail([email protected]', $subject, $emailBody); 

// Now we can print out a message to them, depending on what they said 
$outputMessage = ($RSVP == 'not') ? "We're really sorry you can't make it!" : "We can't wait to see you at the venue in August!"; 
?> 

<div> 
    <strong>Thanks so much for RSVPing!</strong><br> 
    <?=$outputMessage?><br><br> 

    - Sarah &amp; Gavin  
</div> 
<? 
} 
else 
{ 
?> 

<form id="RSVP_Form" name="form1" method="post" action="?submit=true"> 
    <div> 
     <label for="Name">Name:</label> 
     <input name="Name" type="text" id="Name" size="30"> 
    </div> 
    <div> 
     <label for="Email">Email:</label> 
     <input name="Email" type="email" id="Email" size="30"> 
    </div> 
    <div> 
     <label>RSVP:</label> 
     <input name="RSVP" type="radio" value='attending'>Attending 
     <label></label> 
     <br><input name="RSVP" type="radio" value='not'>Not Attending 
    </div> 
    <div> 
     <label for="ReplyFor">Replying For:</label> 
     <select name="ReplyFor" id="ReplyFor"> 
      <option value="1" selected="selected">Yourself Only</option> 
      <option value="2">Yourself + 1 other invited guest</option> 
      <option value="3">Yourself + 2 other invited guest</option> 
      <option value="4">Yourself + 3 other invited guest</option> 
      <option value="5">Yourself + 4 other invited guest</option> 
     </select> 
    </div> 
    <div> 
     <label for="message">Message:</label> 
     <textarea name="message" id="message" rows="3" cols="26"></textarea> 
    </div> 
    <div></div> 
    <div id="submit"> 
     <input name="Submit" type="submit" value=" Submit "> 
    </div> 
</form> 
<? 
} 
?> 


</div> 
</div> 
</body> 
</html> 
+0

和錯誤會是? – Gntem

+0

代碼很長,如果您還可以提到您在運行代碼時遇到的錯誤,它對我們會更有幫助。 – Teocci

+0

爲什麼你在'

'標籤中有方法'POST'並且你用GET來捕捉按鈕?這兩個必須匹配。 –

回答

3

退房這一行:

mail([email protected]', $subject, $emailBody); 

你缺少的電子郵件地址之前,一個單引號。