html - PHP auto responder -



html - PHP auto responder -

i made php form can't figgure out how create auto respond email filled in. want send confurmation person used form have dont know how create it.

here illustration of code. want send custom mail service $email how do that?!

i made changes dont recive emails jet. maby did understand whrong can check me 1 time again please.

<?php /* set e-mail recipient */ $myemail = "opgeven@kidsnthingspernis.nl"; /* check form inputs using check_input function */ $subject = check_input($_post['subject']); $voornaam = check_input($_post['voornaam'], "vul a.u.b. uw voornaam in."); $achternaam = check_input($_post['achternaam'], "vul a.u.b. uw achternaam in."); $voornaamkind = check_input($_post['voornaamkind'], "vul a.u.b. de voornaam van uw in."); $achternaamkind = check_input($_post['achternaamkind'], "vul a.u.b. de achternaam van uw in."); $email = check_input($_post['email'], "vul a.u.b. uw email adres in."); $leeftijd = check_input($_post['leeftijd'], "vul a.u.b. de leeftijd van uw kind in."); $groep = check_input($_post['groep'], "vul a.u.b. de basisschoolgroep van uw in."); $opmerking= ($_post['opmerking']); /* if e-mail not valid show error message */ if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) { show_error("e-mail adres klopt niet"); } /* let's prepare message e-mail */ $message = "hallo! je contact formulier ingevuld door: ouder/verzorger voornaam: $voornaam achternaam: $achternaam kind: voornaam kind: $voornaamkind achternaam kind: $achternaamkind e-mail: $email groep: $groep leeftijd: $leeftijd opmerking: $opmerking einde bericht. " ; /* send message using mail() function */ mail($myemail, $subject, $message); /* redirect visitor give thanks page */ header('location: bedankt.html'); exit(); /* functions used */ function check_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if (strlen($data) == 0) { homecoming false; } else { homecoming $data; } } function show_error($myerror) { ?> <html> <body> <b>please right next error:</b><br /> <?php echo $myerror; ?> </body> </html> <?php $email = 'email'; $subject = 'subject'; $message = "hallo! u/jij bent nu opgegeven voor kids n theatre met de vliegende speeldoos. dit wat wij aan gegevens hebben gekregen: ouder/verzorger voornaam: $voornaam achternaam: $achternaam kind: voornaam kind: $voornaamkind achternaam kind: $achternaamkind e-mail: $email groep: $groep leeftijd: $leeftijd opmerking: $opmerking einde bericht. "; $headers = 'from: opgeven@kidsnthingspernis.nl' . "\r\n" . 'reply-to: opgeven@kidsnthingspernis.nl' . "\r\n" . 'x-mailer: php/' . phpversion(); mail($email, $subject, $message, $headers); ?> <?php exit(); } ?>

there multiple errors in way you've setup script, allow me seek , point them out you.

first of all, you're using header('location..., irrespective of if of show_error functions beingness echoed / printed above it, result in error of...

warning: cannot modify header info - headers sent by

this because not allowed output before header (read more in php documentation of header).

so avoid this, you'll have tell script somehow there error, , check against it, allow header executed if there no errors.

in case, i'd remove $problem variable check_input function, , turn array of error messages instead. way able output multiple error messages, if there multiple form inputs have not been filled in correctly:

$problem = array();

i'd modify check_input function return false in case validation fails:

function check_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if (strlen($data) == 0) { homecoming false; } else { homecoming $data; } }

further up, according changes, i'd utilize function next way:

$leeftijd = check_input($_post['leeftijd']); if (!$leeftijd) { $problem[] = "vul a.u.b. uw leeftijd in."; // square brackets ('[]') 1 of ways add together element array }

i'd avoid using show_error way, cause same error header because you're, plain , simple, outputting html code using function above it.

consequently utilize when checking against $problem array, , if there errors, otherwise allow send email. work properly, you'd have modify little:

function show_error($myerror) { ?> <html> <body> <b>please right next error(s):</b><br /> <?php foreach($myerror $error) // `foreach` function takes care of looping through array { echo $myerror."<br />"; // adding line break able show multiple errors } ?> </body> </html> <?php } ?>

then i'd utilize final check , above modified function next way:

if (count($problem) > 0) { show_error($problem); } else { mail($myemail, $subject, $message); }

i know there many other ways this, found 1 modified existing script to the lowest degree providing 1 of ideal results.

note: know curly brackets ({ , }) not necessary, it's best newby start with.

php html forms email

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -