0

I need some help. Could someone help me with this code. I need a PHP Script inside this HTML for this booking to send emails properly. Cause it this case it opens a mail program like thunderbird, outlook, gmail and any stuff like this. I really need that the PHP is INSIDE the HTML. I am using software that reads only HTML and JAVA. Thank you.

<!DOCTYPE HTML>
<html>
	<meta charset="UTF-8">
	<title>Hotel Booking Form</title>
<body>
	<form action="mailto:email name" method="GET">
	<fieldset>
		<legend>Personal Details:</legend>
		<label for="name">Username: </label><input type="text" name="username" id="name" required autofocus placeholder="Your username" pattern="[a-zA-Z]{3,}" title="Please enter more than three letters">
        <label for="email">Email: </label><input type="text" name="email" id="email" required placeholder="Your Email" pattern="[a-zA-Z]{3,}@[a-zA-Z]{3,}[.]{1}[a-zA-Z]{2,}" title="Please enter a valid email adress">
     	<label for="phone">Phone:</label><input type="tel" name="phone" id="phone"  required placeholder="Please enter your phone number" pattern="[0-9]{4} [0-9]	{3}" title="Please enter a phone number in this format: #### ### ###" >
        </fieldset>
        <br>
        <fieldset>
        <legend>Booking Detals:</legend>
        <label for="date"> Booking Date:</label> <input id="date" type="date" name="date" min="2013-12-02">
        <label for="numberOfGuests">Number Of Guests</label><input id="numberOfGuests" type="number" name="numberOfGuests" min="1" max="6">
        <p>Do you require meals?</p>
        <label for="yesMeals">Yes</label><input id="yesMeals" type="radio" name="meals" value="yesMeals">
       <label for="noMeals">No</label> <input id="noMeals" type="radio" name="meals" value="noMeals">
		<br>
        <input type="image" src="http://designshack.net/images/designs/submit-button_2.jpg">
                </fieldset>

</body>
</html>

2 Answers 2

1

You'll need to change the action of the form to a PHP script (which needs to be the same name as what you have your HTML in). And add a submit button (I don't see it here?). Then at the top of your script you will collect the values of $_GET into a string and use the mail() function to send it.

<?php
if (isset($_GET['my_submit_button'])) {
    $body = "Email: $_GET[email]<br />\n";
    $body .="Phone: $_GET[phone]<br />\n";
    $body .="Number of Guests: $_GET[numberOfGuests]<br />\n";
    # etc.
    mail("[email protected]", "Your Subject", $body);
} 
?>
<html> ... here you put your actual form - the code that you already have
<?php
}

The above is oversimplified, but, the idea is just to get you going in the right direction.

Sign up to request clarification or add additional context in comments.

10 Comments

This is a great point to go, but i was only asking if someone can explain me how to put the PHP code inside the HTML i mean i know how to do it seperatly but dont know how to put it together?
Since you are submitting to the same script you can just leave the action="foo.php" attribute out of the form attribute entirely and it will automatically submit on itself.
<?php if (isset($_GET['my_submit_button'])) { $body = "Email: $_GET[email]; $body ="Phone: $_GET[phone]; $body ="Number of Guests: $_GET[numberOfGuests]; $body ="date" $_GET[date]; mail("[email protected]", "Your Subject", $body); } ?> It is smth like this?
But now the problem is that all data that is inside its saved into my browsers tab..
Sorry, I'm not clear on that last comment - "saved into your browser's tab"? On the previous question there is a big difference between = and .= (with a period before the equals). The former overwrites on assignment while the latter appends on assignment. Maybe the font isn't allowing me to see your periods, but it looks like they aren't there.
|
1

first change this

<form action="mailto:email name" method="GET">

to

<form action="" method="GET">

and at the end of file

<?php
if(isset($_GET)){
  $email = $_GET['email'];
  if (!filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
    echo("$email is a valid email address");
    # and use PHP's mail function to send email
  }
}

Reference to function

Edit

edited

1 Comment

I need to be in one file. I mean inside the HEAD tag or smth?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.