PHP-Programm zum Senden von Formularen an E-Mail
Kürzlich wurde die Website überarbeitet und ich wollte ein Programm erstellen, das Online-Formulare an eine E-Mail-Adresse sendet. Viele Lösungen funktionierten nicht, also habe ich schließlich selbst eine entwickelt.
<html><body><?phpfunction spamcheck($field) { //filter_var() sanitizes the e-mail //address using FILTER_SANITIZE_EMAIL $field=filter_var($field, FILTER_SANITIZE_EMAIL);
//filter_var() validates the e-mail //address using FILTER_VALIDATE_EMAIL if(filter_var($field, FILTER_VALIDATE_EMAIL)) { return TRUE; } else { return FALSE; } }
if (isset($_REQUEST['w_14'])) {//if "email" is filled out, proceed
//check if the email address is invalid $mailcheck = spamcheck($_REQUEST['w_14']); $w_1_check = $_REQUEST['w_1']; $w_8_check = $_REQUEST['w_8']; $w_13_check = $_REQUEST['w_13']; if ($mailcheck==FALSE) { echo "<script language=\"JavaScript\">\r\n"; echo " alert(\"Bitte füllen Sie Ihre E-Mail sorgfältig aus, damit unsere Mitarbeiter Sie kontaktieren können. Vielen Dank für Ihre Kooperation!\");\r\n"; echo " history.back();\r\n"; echo "</script>"; } if ($w_1_check=='') { echo "<script language=\"JavaScript\">\r\n"; echo " alert(\"Bitte füllen Sie den Firmennamen sorgfältig aus, damit unsere Mitarbeiter Sie kontaktieren können. Vielen Dank für Ihre Kooperation!\");\r\n"; echo " history.back();\r\n"; echo "</script>"; } if ($w_8_check=='') { echo "<script language=\"JavaScript\">\r\n"; echo " alert(\"Bitte füllen Sie Ihren Namen sorgfältig aus, damit unsere Mitarbeiter Sie kontaktieren können. Vielen Dank für Ihre Kooperation!\");\r\n"; echo " history.back();\r\n"; echo "</script>"; } if ($w_13_check=='') { echo "<script language=\"JavaScript\">\r\n"; echo " alert(\"Bitte füllen Sie Ihre QQ/MSN-Nummer sorgfältig aus, damit unsere Mitarbeiter Sie kontaktieren können. Vielen Dank für Ihre Kooperation!\");\r\n"; echo " history.back();\r\n"; echo "</script>"; } else {//send email $email = $_REQUEST['w_14'] ; $subject = $_REQUEST['w_1'] . " " . $_REQUEST['w_8'] ; $message = "Firmenname :". $_REQUEST['w_1'] . "\r\n" . "Website-Sprachen :". $_REQUEST['w_2_1'] . "/" . $_REQUEST['w_2_2'] . "/" . $_REQUEST['w_2_3'] . "/" . $_REQUEST['w_2_4'] . "/" . $_REQUEST['w_2_5'] . "/" . "\r\n" . "Referenz-Websites :". $_REQUEST['w_3'] . "\r\n" . "Geschäftsbeschreibung :". $_REQUEST['w_4'] . "\r\n" . "Budget :". $_REQUEST['w_5'] . "-" . $_REQUEST['w_6'] . "\r\n" . "Erwartete Fertigstellung :". "Gewünschtes Fertigstellungsdatum" . $_REQUEST['w_7'] . "\r\n" . " Gewünschte Fertigstellungstage" . $_REQUEST['w_7_1'] . "\r\n" . "Sonstige Anforderungen :". $_REQUEST['w_7_2'] . "\r\n" . "=============================================================" . "\r\n" . "Name :". $_REQUEST['w_8'] . "\r\n" . "Geschlecht :". $_REQUEST['w_9'] . "\r\n" . "Telefon :". $_REQUEST['w_11'] . "\r\n" . "Mobil :". $_REQUEST['w_12'] . "\r\n" . "QQ/MSN :". $_REQUEST['w_13'] . "\r\n" . "E-Mail :". $_REQUEST['w_14'] . "\r\n" . "Skype :". $_REQUEST['w_15'] . "\r\n" . "Postleitzahl :". $_REQUEST['w_16'] . "\r\n" . "Detaillierte Adresse :". $_REQUEST['w_17'] . "\r\n"; mail("admin@zhaojian.net", "$subject Website-Entwicklungsanfrage.", $message, "From: $email"); echo "<script language=\"JavaScript\">\r\n"; echo "alert(\"Informationen erfolgreich übermittelt! Bitte warten Sie auf die Kontaktaufnahme unserer Mitarbeiter. Automatische Rückkehr zur Startseite\");\r\n"; echo "location.replace(\"http://www.zhaojian.net/\");\r\n"; echo "</script>"; } }else {//if "email" is not filled out, display the form echo "<form id='form1' action='http://www.zhaojian.net/b/b.php' method='post' name='form1'> <table class='table_1' cellspacing='0' cellpadding='0' width='675' border='0'> <tbody> <tr> <th colspan='2'>Website-Entwicklungsantragsformular</th> </tr> <tr> <td class='input_1' width='125'>Firmenname</td> <td class='input_2' width='550'><input class='input_text' style='width: 300px' name='w_1' type='text' /></td> </tr> <tr> <td class='input_1' width='125'>Website-Sprachen</td> <td class='input_2' width='550'><input type='checkbox' checked='checked' name='w_2_1' value='Vereinfachtes Chinesisch' /> <label for='w_2_1'>Vereinfachtes Chinesisch</label> <input type='checkbox' name='w_2_2' value='Traditionelles Chinesisch' /> <label for='w_2_2'>Traditionelles Chinesisch</label> <input type='checkbox' name='w_2_3' value='Englisch' /> <label for='w_2_3'>Englisch</label> <input type='checkbox' name='w_2_4' value='Japanisch' /> <label for='w_2_4'>Japanisch</label> <input type='checkbox' name='w_2_5' value='Andere Sprachen' /> <label for='w_2_5'>Andere Sprachen</label></td> </tr> <tr> <td class='input_1' width='125'>Referenz-Websites</td> <td class='input_2' width='550'><input style='width: 300px' name='w_3' type='text' /></td> </tr> <tr> <td class='input_1' width='125'>Geschäftsbeschreibung</td> <td class='input_2' width='550'><textarea class='input_text' style='width: 300px' name='w_4'></textarea></td> </tr> <tr> <td class='input_1' width='125'>Budget</td> <td class='input_2' width='550'><input class='input_text' name='w_5' type='text' /> -- <input class='input_text' name='w_6' type='text' /> EUR</td> </tr> <tr> <td class='input_1' width='125'>Erwartete Fertigstellung</td> <td class='input_2' width='550'><input class='input_text' name='w_7' value='Gewünschtes Fertigstellungsdatum' type='text' /> <input class='input_text' name='w_7_1' value='Gewünschte Fertigstellungstage' type='text' /> Tage</td> </tr> <tr> <td class='input_1' width='125'>Sonstige Anforderungen</td> <td class='input_2' width='550'><textarea class='input_text' style='width: 300px' name='w_7_2'></textarea></td> </tr> </tbody> </table> <table class='table_1' cellspacing='0' cellpadding='0' width='675' border='0'> <tbody> <tr> <th colspan='4'>Kontaktinformationen</th> </tr> <tr> <td class='input_1' width='129'>Name</td> <td class='input_2' width='202'><input name='w_8' type='text' /></td> <td class='input_1' width='96'>Geschlecht</td> <td class='input_2' width='246'><input type='radio' checked='checked' name='w_9' value='Frau' />Frau <input type='radio' name='w_9' value='Herr' />Herr</td> </tr> <tr> <td class='input_1' align='left'>Telefon</td> <td class='input_2'><input class='input_text' name='w_11' type='text' /></td> <td class='input_1'>Mobil</td> <td class='input_2'><input name='w_12' type='text' /></td> </tr> <tr> <td class='input_1'>QQ / MSN</td> <td class='input_2'><input class='input_text' name='w_13' type='text' /></td> <td class='input_1'>E-Mail</td> <td class='input_2'><input name='w_14' type='text' /></td> </tr> <tr> <td class='input_1'>Skype</td> <td class='input_2'><input class='input_text' name='w_15' type='text' /></td> <td class='input_1'>Postleitzahl</td> <td class='input_2'><input name='w_16' type='text' /></td> </tr> <tr> <td class='input_1'>Detaillierte Adresse</td> <td class='input_2'><input name='w_17' type='text' /></td> <td class='input_1'>Firmenadresse</td> <td class='input_2'><input name='w_172' type='text' /></td> </tr> </tbody> </table>
<table class='table_1' cellspacing='0' cellpadding='0' width='675' border='0'> <tbody> <tr> <td class='input_2'> <div align='center'><input id='send_mail_agent' type='submit' name='w_18' value='Submit' /></div> </td> </tr> </tbody> </table> </form>"; }?>
</body></html>