gastroll Posted March 2, 2011 Share Posted March 2, 2011 Hez guys, first of all I have to admit that I have NO clue about php and building an contact form is my first contact with it. However I use the following contact form: <form id="formID" class="formular" action="restaurant-kontakt-sent.php" method="post" > <fieldset> <legend> Persönliche Angaben </legend> <table> <tr> <td> <span style="color:#FF0000">*</span><span>Name:</span> </td> <td> <label> <input value="<?=$_SESSION['post']['name']?>" class="validate[required,custom[onlyLetterSp]] text-input" type="text" name="name" id="name" /> </label> </td> </tr> <tr> <td> <span style="color:#FF0000">*</span><span>Email: </span> </td> <td> <label> <input value="<?=$_SESSION['post']['email']?>" class="validate[required,custom[email]] text-input" type="text" name="email" id="email" /> </label> </td> </tr> <tr> <td> <span>Adresse:</span> </td> <td> <label> <input value="<?=$_SESSION['post']['adresse']?>" class="validate[custom[onlyLetterNumber]] text-input" type="text" name="adresse" id="adresse" /> </label> </td> </tr> <tr> <td> <span>Telefon: </span><br><span style="font-size:9px;">(Bitte mit Vorwahl)</span> </td> <td> <label> <input value="<?=$_SESSION['post']['tele']?>" class="validate[custom[phone]] text-input" type="text" name="tele" id="tele" /> </label> </td> </tr> </table> </fieldset> <fieldset> <legend> Weitere Angaben </legend> <table> <tr> <td> <span>Unternehmen:</span> </td> <td> <label> <input value="<?=$_SESSION['post']['uname']?>" class="validate[custom[onlyLetterNumber]] text-input" type="text" name="uname" id="uname" /> </label> </td> </tr> <tr> <td> <span>Website:</span> </td> <td> <label> <input value="http://" class="validate[custom[url]] text-input" type="text" name="website" id="website" /> </label> </td> </tr> <tr> <td> <span>Unternehmen <br>zuordnen:</span> </td> <td> <label> <select name="unternehmenstyp" id="unternehmenstyp" class="validate[custom]"> <option value="option1">Bars, Pubs & Kneipen</option> <option value="option2">Cafes & Bistros</option> <option value="option3">Catering & Partyservice</option> <option value="option1">Clubs & Diskotheken</option> <option value="option2">Events & Veranstaltungen</option> <option value="option3">Imbiss, Pizza & Fast Food</option> <option value="option1">Kinos</option> <option value="option2">Lieferservice</option> <option value="option3">Pensionen, Hostels & Jugendherbergen</option> <option value="option3">Restaurants</option> <option value="option3">Andere</option> </select> </td> </tr> </table> </label> </fieldset> <fieldset> <legend> Ihre Nachricht </legend> <table> <tr> <td> <span>Betreff:</span> </td> <td> <label> <input value="<?=$_SESSION['post']['betreff']?>" class="validate[custom[onlyLetterNumber]] text-input" type="text" name="betreff" id="betreff" /> </label> </td> </tr> <tr> <td> <span>Nachricht:</span> </td> <td> <label> <textarea class="validate[required] text-input" rows="4" cols="40" name="anschreiben" id="anschreiben" > <?=$_SESSION['post']['message']?> </textarea> </label> </td> </tr> </table> <!-- <div> <span>Datei zum Anhang hinzufügen:</span> <input class="validate[custom[]] text-input" type="file" name="anhang" id="anhang"/> </div> --> </fieldset> <input class="submit" type="submit" value="Senden!"/><hr/> </form> And the following restaurant-kontakt-sent.php: <?php if(isset($_POST['submit'])) { $to = '[email protected]'; $name = $_POST['name'] ; $email = $_POST['email'] ; $adresse = $_POST['adresse'] ; $telefon = $_POST['tele'] ; $unternehmensname = $_POST['uname'] ; $unternehmenstyp = $_POST['unternehmenstyp'] ; $betreff = $_POST['betreff'] ; $anschreiben = $_POST['anschreiben'] ; //$headers = "From: $Nachname <$Email>"; //$error = ""; //if (trim($nachname)=="" || trim($email)==""|| trim($anschreiben)=="" ) //{ //$error = "Ooops! Nachname, Emailadresse und Anschreiben sind Pflichtfelder." //} mail($to, $vorname, $nachname, $email, $adresse, $telefon, $unternehmensname, $unternehmenstyp, $betreff, $anschreiben) ; if (mail($to, $vorname, $nachname, $email, $adresse, $telefon, $unternehmensname, $unternehmenstyp, $betreff, $anschreiben)) header("Location:/restaurant-kontakt-gesendet.html"); else header("Location:/restaurant-kontakt-error.html"); } ?> My problem is: 1. There is no mail coming (my host is 1und1.de and it is not inside the span or junk folder)? 2. And after pushing the submit button the user gets not passed to the the restaurant-kontakt-error.html or restaurant-kontakt-gesendet.html. Could anyone give me the right direction? Quote Link to comment https://forums.phpfreaks.com/topic/229336-contact-form-problem/ Share on other sites More sharing options...
kenrbnsn Posted March 2, 2011 Share Posted March 2, 2011 You are not using the mail() function correctly. Read the manual page. Ken Quote Link to comment https://forums.phpfreaks.com/topic/229336-contact-form-problem/#findComment-1181691 Share on other sites More sharing options...
Twistedweb123 Posted March 2, 2011 Share Posted March 2, 2011 I believe you are confusing how the mail() function works. The mail functions requires certain inputs to send. Such as: email address to deliver to email address delivered from the subject the message email headers <?php if(isset($_POST['submit'])) { $to = '[email protected]'; $subject = "New Message"; $name = $_POST['name'] ; $email = $_POST['email'] ; $adresse = $_POST['adresse'] ; $telefon = $_POST['tele'] ; $unternehmensname = $_POST['uname'] ; $unternehmenstyp = $_POST['unternehmenstyp'] ; $betreff = $_POST['betreff'] ; $anschreiben = $_POST['anschreiben'] ; $headers = "From: $from"; $message = " See information from form below,\n\n Name: $name\n Email: $email\n Adresse: $adresse\n Telefon: $telefon\n Unternehmensname: $unternehmensname\n Unternehmenstyp: $unternehmenstyp\n Betreff: $betreff\n Anschreiben: $anschreiben\n\n\n"; // Send the message $sendit = @mail($to, $subject, $message, $headers); if($sendit){ header("Location: /restaurant-kontakt-gesendet.html"); }else{ header("Location: /restaurant-kontakt-error.html"); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/229336-contact-form-problem/#findComment-1181692 Share on other sites More sharing options...
Twistedweb123 Posted March 2, 2011 Share Posted March 2, 2011 slight error in my last post change: $headers = "From: $from"; to: $headers = "From: $email"; Quote Link to comment https://forums.phpfreaks.com/topic/229336-contact-form-problem/#findComment-1181693 Share on other sites More sharing options...
gastroll Posted March 3, 2011 Author Share Posted March 3, 2011 Hey Twistedweb123, thanks for your post: I put your changes in my file. Here is my new file: <?php if(isset($_POST['submit'])) { $to = '[email protected]'; $subject = $_POST['betreff'] ; $name = $_POST['name'] ; $email = $_POST['email'] ; $adresse = $_POST['adresse'] ; $telefon = $_POST['tele'] ; $unternehmensname = $_POST['uname'] ; $website = $_POST['website'] ; $unternehmenstyp = $_POST['unternehmenstyp'] ; $anschreiben = $_POST['anschreiben'] ; $headers = "From: $email"; $message = " See information from form below,\n\n Betreff: $betreff\n Name: $name\n Email: $email\n Adresse: $adresse\n Telefon: $telefon\n Unternehmensname: $unternehmensname\n Website: $website\n Unternehmenstyp: $unternehmenstyp\n Anschreiben: $anschreiben\n\n\n"; // Send the message $sendit = @mail($to, $subject, $message, $headers); if($sendit){ header("Location: /restaurant-kontakt-gesendet.html"); }else{ header("Location: /restaurant-kontakt-error.html"); } } ?> But: (tested different email addresses) - did not received a email (no spam) - and after submitting the user is not redirected to the thank-you.html Any further idea? Quote Link to comment https://forums.phpfreaks.com/topic/229336-contact-form-problem/#findComment-1182293 Share on other sites More sharing options...
onlyican Posted March 3, 2011 Share Posted March 3, 2011 Basic test to find out if your email mail() is working. NOTE: this will have NO headers and most likely end up in your Junk email box. Will also be from your server not u. Try it and we can go from there. $strTo = '[email protected]'; $strSubject = 'My Test Email'; $strBody = 'This is the Email message'; if(mail($strTo, $strSubject, $strBody){ echo 'Mail has been sent'; }else{ echo 'This is going to cause a headache'; } Quote Link to comment https://forums.phpfreaks.com/topic/229336-contact-form-problem/#findComment-1182294 Share on other sites More sharing options...
gastroll Posted March 26, 2011 Author Share Posted March 26, 2011 Hi, sorry that I respond so late (have been in holiday for a while). So put your test version in my file and it did not work out. here is my new php file. <?php $strTo = '[email protected]'; $strSubject = 'My Test Email'; $strBody = 'This is the Email message'; if(mail($strTo, $strSubject, $strBody){ echo 'Mail has been sent'; }else{ echo 'This is going to cause a headache'; } ?> after submit the browser tells me: Parse error: syntax error, unexpected '{' in /homepages/xx/xxx/htdocs/xxx.de/kontakt-sent.php on line 5 Quote Link to comment https://forums.phpfreaks.com/topic/229336-contact-form-problem/#findComment-1192469 Share on other sites More sharing options...
kenrbnsn Posted March 26, 2011 Share Posted March 26, 2011 You're missing a closing ")" on this line: <?php if(mail($strTo, $strSubject, $strBody){ ?> it should be <?php if(mail($strTo, $strSubject, $strBody)){ ?> BTW, when posting code, please put the code between tags. Ken Quote Link to comment https://forums.phpfreaks.com/topic/229336-contact-form-problem/#findComment-1192536 Share on other sites More sharing options...
gastroll Posted March 28, 2011 Author Share Posted March 28, 2011 Ups, sorry next time I will use the right code highlight thing. Fiiinaly I got a email in my account: the test mail worked. So can anyone see what I am doing wrong on my original kontakt-sent.php? : <?php if(isset($_POST['submit'])) { $to = '[email protected]'; $subject = $_POST['betreff'] ; $name = $_POST['name'] ; $email = $_POST['email'] ; $adresse = $_POST['adresse'] ; $telefon = $_POST['tele'] ; $unternehmensname = $_POST['uname'] ; $website = $_POST['website'] ; $unternehmenstyp = $_POST['unternehmenstyp'] ; $anschreiben = $_POST['anschreiben'] ; $headers = "From: $email"; $message = " See information from form below,\n\n Betreff: $betreff\n Name: $name\n Email: $email\n Adresse: $adresse\n Telefon: $telefon\n Unternehmensname: $unternehmensname\n Website: $website\n Unternehmenstyp: $unternehmenstyp\n Anschreiben: $anschreiben\n\n\n"; // Send the message $sendit = @mail($to, $subject, $message, $headers); if($sendit){ header("Location: http://www.mywebsite.de/kontakt-gesendet.html"); }else{ header("Location: http://www.mywebsite.de/kontakt-error.html"); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/229336-contact-form-problem/#findComment-1193155 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.