Hallo!
Ich bin leider absoluter PHP-Anfänger, und hoffe, mir kann Jemand hier helfen.
Ich erstelle momentan eine Inernet-Seite, und nutze dafür ein HTML-Template. Dieses Template enthält auch ein (PHP-)E-Mail-Formular, welches ich anpassen möchte. Irgendwie schaffe es das aber nicht...
Original:
Code in der HTML-Datei
PHP-Code
Das Formular auf der HTML-Seite habe ich geändert:
Leider schaffe ich es nicht, die PHP-Datei so anzupasen, dass alle Felder übermittelt werden. Hätte Jemand eine Idee?
Vielen Dank!!!
arneg
Ich bin leider absoluter PHP-Anfänger, und hoffe, mir kann Jemand hier helfen.
Ich erstelle momentan eine Inernet-Seite, und nutze dafür ein HTML-Template. Dieses Template enthält auch ein (PHP-)E-Mail-Formular, welches ich anpassen möchte. Irgendwie schaffe es das aber nicht...
Original:
Code in der HTML-Datei
Code:
<form action='index.html' method='post' id='contact_form'> <h3>Contact Form</h3> <div class="hr dotted clearfix"> </div> <ul> <li class="clearfix"> <label for="name">Name</label> <input type='text' name='name' id='name' /> <div class="clear"></div> <p id='name_error' class='error'>Insert a Name</p> </li> <li class="clearfix"> <label for="email">Email Address</label> <input type='text' name='email' id='email' /> <div class="clear"></div> <p id='email_error' class='error'>Enter a valid email address</p> </li> <li class="clearfix"> <label for="subject">Subject</label> <input type='text' name='subject' id='subject' /> <div class="clear"></div> <p id='subject_error' class='error'>Enter a message subject</p> </li> <li class="clearfix"> <label for="message">Message</label> <textarea name='message' id='message' rows="30" cols="30"></textarea> <div class="clear"></div> <p id='message_error' class='error'>Enter a message</p> </li> <li class="clearfix"> <p id='mail_success' class='success'>Thank you. I'll get back to you as soon as possible.</p> <p id='mail_fail' class='error'>Sorry, an error has occured. Please try again later.</p> <div id="button"> <input type='submit' id='send_message' class="button" value='Submit' /> </div> </li> </ul> </form>
PHP-Code:
<?php
//we need to get our variables first
include 'config.php';
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
/*the $header variable is for the additional headers in the mail function,
we are asigning 2 values, first one is FROM and the second one is REPLY-TO.
That way when we want to reply the email gmail(or yahoo or hotmail...) will know
who are we replying to. */
$headers = "From: $email\r\n";
$headers .= "Reply-To: $email\r\n";
if(mail($email_to, $subject, $message, $headers)){
echo 'sent'; // we are sending this text to the ajax request telling it that the mail is sent..
}else{
echo 'failed';// ... or this one to tell it that it wasn't sent
}
?>
Code:
<form action='index.html' method='post' id='contact_form'> <h3>Anmeldeformular</h3> <div class="hr dotted clearfix"> </div> <ul> <li class="clearfix"> <label for="name">Name</label> <input type='text' name='name' id='name' /> <div class="clear"></div> <p id='name_error' class='error'>Bitte Namen eingeben</p> </li> <li class="clearfix"> <label for="adresse">Adresse</label> <input type='text' name='adresse' id='adresse' /> <div class="clear"></div> <p id='adresse_error' class='error'>Bitte Adresse eingeben</p> </li> <li class="clearfix"> <label for="email">Email-Adresse</label> <input type='text' name='email' id='email' /> <div class="clear"></div> <p id='email_error' class='error'>Bitte eine gültige Email-Adresse eingeben</p> </li> <li class="clearfix"> <label for="telefon">Telefon</label> <input type='text' name='telefon' id='telefon' /> <div class="clear"></div> <p id='telefon_error' class='error'>Bitte Telefon-Nr. eingeben</p> </li> <li class="clearfix"> <label for="message">Wie haben Sie von uns erfahren?</label> <textarea name='message' id='message' rows="30" cols="30"></textarea> <div class="clear"></div> <p id='message_error' class='error'>Bitte Nachricht eingeben</p> </li> <li class="clearfix"> <p id='mail_success' class='success'>Vielen Dank! Die Anmeldung wurde versendet.</p> <p id='mail_fail' class='error'>Ein Fehler ist aufgetreten. Bitte versuchen Sie es später noch einmal.</p> <div id="button"> <input type='submit' id='send_message' class="button" value='Abschicken' /> </div> </li> </ul> </form>
Vielen Dank!!!
arneg
Kommentar