<form action=“post.php” method=“post”>
<input type=“text” name=“name” placeholder=“Име и Презиме” class=“form-ime-i-prezime input-bidi-clen” autocomplete=“off” required/><br>
<input type=“text” name=“bday” placeholder="Датум на раѓање " class=“form-godini input-bidi-clen” autocomplete=“off” required/><br>
<input type=“e-mail” name=“email” placeholder="Е-маил " class=“form-e-mail input-bidi-clen” autocomplete=“off” required/><br>
<button type=“submit” class=“form-prati-kopce”>Прати</button>
</form>
Hi.
How can i send this form to my e-mail with php?
Thanks.
On your post.php you will need to use the mail function.
I’ve used this snippet on a number of sites, seems to work ok.
Place this code inside post.php or on the same page above the first <html> tag and post the form to itself.
You might need to make a few tweaks to match your inputs, should give you a good start.
session_start();
$name = '';
$email = '';
$tel = '';
$comment = '';
$s_error_message = '';
if (isset($_POST['submit'])) { //check for name of your submit button
if (isset($_POST['name'])) {
$name = trim(stripslashes($_POST['name']));
}
if (isset($_POST['email'])) {
$email = trim(stripslashes($_POST['email']));
}
if (isset($_POST['tel'])) {
$tel = trim(stripslashes($_POST['tel']));
}
if (isset($_POST['comment'])) {
$comment = trim(stripslashes($_POST['comment']));
}
if (strlen($name) == 0) {
$s_error_message .= "» Enter your name<br>";
}
if (strlen($email) == 0) {
$s_error_message .= "» Enter your email<br>";
} elseif (!eregi("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\\.[a-z]{2,4}$", $email)) {
$s_error_message .= "» Not a valid email<br>";
}
if (strlen($s_error_message) == 0) {
$to = "email@someaddress.com";
$message = "Name: " . $name . "\
\
" . $comment . "\
\
Tel: " . $tel . "\
Email: " . $email;
$subject = "Website Query";
if (mail($to, $subject, $message, 'From: ' . $email)) {
header('Location: http://www.yoursitename.com/thank-you.html');
} else {
print('There was a problem sending the mail. Please check that you filled in the form correctly.');
}
}
}
This will show any errors to the user, place in a div above the form.
<strong><?php if (strlen($s_error_message) > 0) {print($s_error_message);} ?></strong>
<form name="contact" method="post" action="post.php">
<fieldset>
<ol>
<li>
<label for="name">Name: <strong>required</strong></label>
<input id="name" name="name" class="text required" type="text" value="<?php print htmlspecialchars($name); ?>">
</li>
<li>
<label for="email">Email address: <strong>required</strong></label>
<input id="email" name="email" class="email required" type="text" value="<?php print htmlspecialchars($email); ?>">
</li>
<li>
<label for="tel">Telephone:</label>
<input id="tel" name="tel" class="text" type="text" value="<?php print htmlspecialchars($tel); ?>">
</li>
<li>
<label for="comment">Message:</label>
<textarea id="comment" name="comment" class="text"><?php print htmlspecialchars($comment); ?></textarea>
</li>
</ol>
</fieldset>
<fieldset class="submit">
<input name="submit" type="submit" value="Submit Message" class="submit">
</fieldset>
</form>
Barry
i tried this code but it doesn’t work because in php haven’t any function to send to my e-mail.
This line sends the email:
if (mail($to, $subject, $message, 'From: ' . $email)) {
Did you customise the code to your email and website details?
yes i customised for me but didn’t work.
And i use XAMPP.
If you are using XAMPP on a localhost you will need to set it up to send emails. I can not remember how at the moment.