I want to display $atendee_name
and $atendee_email
in form content but it does not work, although it works in another section.
HTML code:
<!-- RSVP section -->
<section id="rsvp">
<div class="rsvp-form-wrap">
<h2>RSVP</h2>
<p class="rsvp-desc"> WE'RE SO EXCITED TO CELEBRATE WITH YOU </p>
<form id="rsvp-form" action="sendmail.php" method="post" data-abide>
<div class="columns large-12">
<label for="atendee-name">Name (required)</label>
<input id="atendee-name" name="atendee_name" type="text" placeholder="John Doe" required pattern="[a-zA-Z]+">
<small class="error">Please enter your name.</small>
</div><!-- End .large-12 -->
<div class="columns large-12">
<label for="atendee-email">Email Address (required)</label>
<input id="atendee-email" name="atendee_email" type="email" placeholder="johndoe@email.com" required>
<small class="error">Please enter a valid email.</small>
</div><!-- End .large-12 -->
<div class="columns large-4 medium-4 small-4">
<label for="guests">Guests</label>
<select id="guests" name="guests">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div><!-- End .large-4 -->
<div class="columns large-8 medium-8 small-8">
<label for="attending">I am attending</label>
<select id="attending" name="attending">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</div><!-- End .large-8 -->
<div class="columns large-12">
<input id="rsvp-submit" class="button" type="submit" value="Submit" name="rsvp_submit">
</div><!-- End .large-12 -->
</form>
</div><!-- End .rsvp-form-wrap -->
</section><!-- End #rsvp -->
PHP Code:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$name = $_POST['atendee_name'];
$email = $_POST['atendee_email'];
$guests = $_POST['guests'];
$attending = $_POST['attending'];
$formcontent="From: $name \n Attending: $attending \n Guests: $guests";
$recipient = "aida.ufe@gmail.com";
$subject = "RSVP form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You! Message successfully sent.";
?>
Error:
Notice: Undefined index: atendee_name in /home/ayoudz/public_html/sendmail.php on line 5Notice: Undefined index: atendee_email in /home/ayoudz/public_html/sendmail.php on line 6
Write your php code in if condition like below
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
if(isset($_POST['rsvp_submit']))//added this line
{
$name = $_POST['atendee_name'];
$email = $_POST['atendee_email'];
$guests = $_POST['guests'];
$attending = $_POST['attending'];
$formcontent="From: $name \n Attending: $attending \n Guests: $guests";
$recipient = "aida.ufe@gmail.com";
$subject = "RSVP form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You! Message successfully sent.";
}// end if here
?>
0 comments:
Post a Comment