2017-04-18 22 views
0

私はPHPを使用して完全な初心者です。私はちょうど私の電子メールアドレスに送信されたWebフォームからいくつかの情報を取得する必要があります。私は1年前にこの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'でボタンをキャッチしていますか?それらの2つは一致しなければならない。 –

答えて

3

この行をチェックアウト:

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

あなたはメールアドレスの前に1つの引用符が欠落しています。

関連する問題