Contents / Previous / Next


Email

Clockwatchers PHP Tutorial: Sending Email


Mini-Web-Mailer (by Daniel Effinger and Johan Rolschewski)

Try the Mini-Web-Mailer or look at the source first: <html> <head> <title>Mini-Web-Mailer</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859"> <link rel="stylesheet" type="text/css" href="style.css"> <script type="text/javascript"> <!-- function nocheinmal(){ document.Formular.empfaenger.value = ""; document.Formular.sender.value = "" document.Formular.message.value = "" document.Formular.subject.value = ""; document.Formular.empfaenger.focus(); } function chk_formular (){ if(document.Formular.empfaenger.value == "") { alert("Bitte den Empfänger eingeben!"); document.Formular.empfaenger.focus(); return false; } if(document.Formular.sender.value == "") { alert("Bitte dem Absender eingeben!"); document.Formular.Ort.focus(); return false; } if(document.Formular.subject.value == "") { alert("Bitte das Subject eingeben!"); document.Formular.Mail.focus(); return false; } if(document.Formular.message.value == "") { alert("Bitte die Nachricht eingeben!"); document.Formular.message.focus(); return false; } } //--> </script> </head> <body> <div align="center"> <span class="head">Mini-Web-Mailer&nbsp;</span><br><br> <form name="Formular" action="mail.php" method="post" onsubmit="chk_formukar()"> <table border="0" cellpadding="5"> <tr> <td>An (eMail Adresse):</td> <td><input type="text" name="empfaenger"></td> </tr> <tr> <td>Von (Deine eMail Adresse):&nbsp;</td> <td><input type="text" name="sender"></td> </tr> <tr> <td>Subject:</td> <td><input type="text" name="subject"></td> </tr> <tr> <td valign="top">Nachricht:</td> <td><textarea cols="20" rows="5" name="message" wrap="hard"></textarea><br><br></td> </tr> <tr> <td>&nbsp;</td> <td><input type="submit" value="go" class="dark">&nbsp;&nbsp;<input type="reset" value="reset" class="dark"></td> </tr> </table> </form> <?php echo "<span class=\"error_msg\">"; if (isset($_REQUEST["empfaenger"]) && $_REQUEST["message"] != ""){ echo "Formular wird verarbeitet !<br>"; $sender = $_REQUEST["sender"]; $subject = $_REQUEST["subject"]; $message = $_REQUEST["message"]; $empfaenger = $_REQUEST["empfaenger"]; //check der email adressen auf gueltigkeit if(!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z]+\.)+[a-z]{2,4}$",$empfaenger)) { echo "<br>Empf&auml;nger-Adresse ung&uuml;ltig !<br>"; echo "<a href=\"javascript:nocheinmal()\">nochmals ?</a>"; } if(!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z]+\.)+[a-z]{2,4}$",$sender)) { echo "<br>Sender-Adresse ung&uuml;ltig !<br>"; echo ""; } // mail() gibt bei erfolg 'true' zurueck if (mail($empfaenger, $subject, $message, "From: ".$sender )){ echo "<br>Jupp, die mail ging raus !!"; }else { echo" <br>Sendefehler !!"; } } echo "</span>"; ?> </div> </body> </html>