Reputation:
I'm struggling a little to create PHP for this HTML code. I'm more of a front end designer than back end any help? here is what have it should be basic yet I have tried myself to get it to work seem to make it worse each time...
HTML CODE
<form action="form.php" method="post" enctype="multipart/form-data">
<label></label>
<input name="name" required placeholder="Your Name">
<label></label>
<input name="email" type="email" required placeholder="Your Email">
<label></label>
<input name="tel" type="tel" placeholder="Your Contact Number">
<label></label>
<select name="treatment">
<option value="">Select...</option>
<option value="">Anti-Wrinkle Injections</option>
<option value="">Dermal Fillers</option>
<option value="">The Vampire Facelift</option>
<option value="">Other Treatments</option>
</select>
<label></label>
<textarea name="message" cols="20" rows="5" required placeholder="Message"></textarea>
<input id="submit" name="submit" type="submit" value="Submit">
</form>
PHP CODE
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: website';
$to = 'email';
$subject = 'Email Inquiry';
$body = "From: {$name}\n E-Mail: {$email}\n Message:\n {$message}";
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Thank you for your email! You will now be redirected to the Home Page.</p>';
} else {
echo '<p>Oops! An error occurred. Try sending your message again.</p>';
}
}
?>
Upvotes: 0
Views: 183
Reputation:
You can use the braces style.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: website';
$to = 'an email address';
$subject = 'Email Inquiry';
$body = "From: {$name}\n E-Mail: {$email}\n Message:\n {$message}";
I hope you also have in mind the safety xss attacks. If not, I suggest a small tutorial like this.
Upvotes: 0
Reputation: 319
Try This.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: website';
$to = 'an email address';
$subject = 'Email Inquiry';
$body = "From: ".$name."<br/>E-Mail: ".$email."<br/> Message:<br/>". $message;
?>
Upvotes: 0
Reputation: 205
This is what the PHP should be:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: website';
$to = 'an email address';
$subject = 'Email Inquiry';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";?>
Its a ? not a / at the end
I just tested the code, using this php, and it works correctly.
Upvotes: 2