02. november 2004 - 13:39
Der er
9 kommentarer og 1 løsning
Formmail med IP afsendelse
Jeg har en formmail der virker og det hele som er skrevet i PHP. MEN jeg vil gerne have den til + de fleter der allerede står der, til at skrive på mailen den sender Afsenderens IP, så jeg undgår evnt spam, da jeg har et "Ban bruger " system på mit site. Her kommer min Formmail kode: <?php session_start(); include("inc/functions.php"); if($_POST[send] && $_POST[besked] != "Besked" && !empty($_POST[emne])){ $_POST[besked] = str_replace("<","<", $_POST[besked]); $_POST[besked] = str_replace(">",">", $_POST[besked]); $_POST[besked] = str_replace(" "," ", nl2br(htmlentities(addslashes($_POST[besked])))); $_POST[besked] = str_replace("","<u>", $_POST[besked]); $_POST[besked] = str_replace(" ","</u>", $_POST[besked]); $_POST[besked] = str_replace("","<u>", $_POST[besked]); $_POST[besked] = str_replace(" ","</u>", $_POST[besked]); $_POST[besked] = str_replace("","<b>", $_POST[besked]); $_POST[besked] = str_replace(" ","</b>", $_POST[besked]); $_POST[besked] = str_replace("","<i>", $_POST[besked]); $_POST[besked] = str_replace(" ","</i>", $_POST[besked]); $_POST[besked] = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\\0\">\\0</a>", $_POST[besked]); $dato = date("d.m.Y -- h:i:s"); $subject = "$_POST[emne]"; $message .= " <html> <head> <style type='text/css'> a {color: #9DBD0D; } a:hover {color: #C0C0C0; } .mg { font-size: 11px; font-family: verdana; color: #9DBD0D; } .m { font-size: 11px; font-family: verdana; color: #595959; } .formmail { background-color: #F8F8F8; border-bottom: #A5ACB2 1px solid; } .ramme{ border-top: #A5ACB2 1px solid; border-right: #A5ACB2 1px solid; border-bottom: #A5ACB2 1px solid; border-left: #A5ACB2 1px solid; } </style> </head> <body> <center> <table border='0' width='500' cellspacing='2' cellpadding='0' class='ramme'> <tr> <td width='100%' valign='top' class='formmail'> <table border='0' width='100%' cellspacing='2' cellpadding='0'> <tr> <td width='99' valign='top'><span class='mg'><b>Dato</b></span></td> <td width='1' valign='top'><span class='mg'>:</span></td> <td width='400' valign='top'><span class='m'>$dato</span></td> </tr> <tr> <td width='99' valign='top'><span class='mg'><b>Emne</b></span></td> <td width='1' valign='top'><span class='mg'>:</span></td> <td width='400' valign='top'><span class='m'>$_POST[emne]</span></td> </tr> <tr> <td width='99' valign='top'><span class='mg'><b>Navn</b></span></td> <td width='1' valign='top'><span class='mg'>:</span></td> <td width='400' valign='top'><span class='m'>$_POST[fra]</span></td> </tr> <tr> <td width='99' valign='top'><span class='mg'><b>E-mail</b></span></td> <td width='1' valign='top'><span class='mg'>:</span></td> <td width='400' valign='top'><span class='m'>$_POST[email]</span></td> </tr> </table> </td> </tr> <tr> <td width='100%' valign='top'><span class='m'>".stripslashes($_POST[besked])."</span></td> </tr> </table> </center> </body> </html>"; $headers = "From: " .$_POST[email]. "<$_POST[email]>\n"; $headers .= "X-Sender: <$_POST[email]>\n"; $headers .= "X-Mailer: PHP\n"; $headers .= "Return-Path: <$_POST[email]>\n"; $headers .= "Content-Type: text/html; charset=iso-8859-1\n"; $headers .= "MIME-Version: 1.0\n"; mail($email, $subject, $message, $headers); header("Location: ".$PHP_SELF."?status=sendt"); } ?> <html> <head> <link rel='stylesheet' type='text/css' href='css/style.css' /> <script langauge="javascript"> <!-- function checkform() { if (document.form.emne.value == "Emne") { alert ('Feltet "emne" skal udfyldes'); return false; } if (document.form.besked.value == "Besked") { alert ('Feltet "besked" skal udfyldes'); return false; } form.submit() } //--> </script> </head> <body> <div class='understreg'><span class='header'>Mail formular</span></div> <br style='font-size: 5px;' /> <br style='font-size: 5px;' /> <?php if($_GET[status] =="sendt"){ echo" <table border='$tableborder' width='$tablewidth' cellspacing='$tablecellspacing' cellpadding='$tablecellpadding'> <tr> <td width='100%' align='center'><span class='mfont'><b>Mail er nu sendt.</b></span></td> </tr> </table>"; }?> <form method='POST' action='<?=$PHP_SELF;?>' name='form'> <table <?php echo"border='$tableborder' width='$tablewidth' cellspacing='$tablecellspacing' cellpadding='$tablecellpadding'"; ?>> <tr> <td width="72%" valign="top" height="15"> <input type="text" name="emne" value="Emne" onfocus="if(this.value=='Emne')this.value='';" onblur="if(this.value=='')this.value='Emne';" size="45" class='input'></td> </tr> <tr> <td width="72%" valign="top" height="15"><input type="text" name="fra" value="Dit navn" onfocus="if(this.value=='Dit navn')this.value='';" onblur="if(this.value=='')this.value='Dit navn';" size="45" class='input'></td> </tr> <tr> <td width="72%" valign="top" height="15"><input type="text" name="email" value="E-mail" onfocus="if(this.value=='E-mail')this.value='';" onblur="if(this.value=='')this.value='E-mail';" size="45" class='input'><span class='sfont'>*</span></td> </tr> <tr> <td width="72%" valign="top" height="15"> <textarea cols="45" rows="10" onfocus="if(this.value=='Besked')this.value=''" onblur="if(this.value=='')this.value='Besked'" id="text" name="besked">Besked</textarea><span class='sfont'>*</span></td> </tr> <tr> <td width="100%" valign="top" height="14"><span class='sfont'>* = Skal udfyldes.</span><br /><input class="inputsend" type="submit" value="Send" name="send" onclick="checkform()"></td> </tr> </table> </form>
Annonceindlæg fra Novataris
02. november 2004 - 13:54
#1
$ip = getenv('REMOTE_ADDR'); mail($email, $subject, $message\n\nAfsenders IP: $ip, $headers);
02. november 2004 - 13:55
#2
Måske: $headers .= "MIME-Version: 1.0\n"; $message = $message . "<br /><br />Afsendt fra: " . $_SERVER['REMOTE_ADDR']; mail($email, $subject, $message, $headers);
02. november 2004 - 13:56
#3
Hvor skal det sættes ind? gider du gøre det og så smide al kode herind ? tak mrmunk.dk/anders
02. november 2004 - 13:57
#4
Jeg kan alligevel ikke huske hvordan man gør, så hold dig til de andre svar :)
02. november 2004 - 13:58
#5
Jeg har kopieret 2 linjer fra dit paste, og indsat 1 linje mellem. Søg efter: $headers .= "MIME-Version: 1.0\n"; ...så burde du kunne se det...
02. november 2004 - 14:00
#6
<?php session_start(); include("inc/functions.php"); if($_POST[send] && $_POST[besked] != "Besked" && !empty($_POST[emne])){ $_POST[besked] = str_replace("<","<", $_POST[besked]); $_POST[besked] = str_replace(">",">", $_POST[besked]); $_POST[besked] = str_replace(" "," ", nl2br(htmlentities(addslashes($_POST[besked])))); $_POST[besked] = str_replace("","<u>", $_POST[besked]); $_POST[besked] = str_replace(" ","</u>", $_POST[besked]); $_POST[besked] = str_replace("","<u>", $_POST[besked]); $_POST[besked] = str_replace(" ","</u>", $_POST[besked]); $_POST[besked] = str_replace("","<b>", $_POST[besked]); $_POST[besked] = str_replace(" ","</b>", $_POST[besked]); $_POST[besked] = str_replace("","<i>", $_POST[besked]); $_POST[besked] = str_replace(" ","</i>", $_POST[besked]); $_POST[besked] = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\\0\">\\0</a>", $_POST[besked]); $dato = date("d.m.Y -- h:i:s"); $subject = "$_POST[emne]"; $message .= " <html> <head> <style type='text/css'> a {color: #9DBD0D; } a:hover {color: #C0C0C0; } .mg { font-size: 11px; font-family: verdana; color: #9DBD0D; } .m { font-size: 11px; font-family: verdana; color: #595959; } .formmail { background-color: #F8F8F8; border-bottom: #A5ACB2 1px solid; } .ramme{ border-top: #A5ACB2 1px solid; border-right: #A5ACB2 1px solid; border-bottom: #A5ACB2 1px solid; border-left: #A5ACB2 1px solid; } </style> </head> <body> <center> <table border='0' width='500' cellspacing='2' cellpadding='0' class='ramme'> <tr> <td width='100%' valign='top' class='formmail'> <table border='0' width='100%' cellspacing='2' cellpadding='0'> <tr> <td width='99' valign='top'><span class='mg'><b>Dato</b></span></td> <td width='1' valign='top'><span class='mg'>:</span></td> <td width='400' valign='top'><span class='m'>$dato</span></td> </tr> <tr> <td width='99' valign='top'><span class='mg'><b>Emne</b></span></td> <td width='1' valign='top'><span class='mg'>:</span></td> <td width='400' valign='top'><span class='m'>$_POST[emne]</span></td> </tr> <tr> <td width='99' valign='top'><span class='mg'><b>Navn</b></span></td> <td width='1' valign='top'><span class='mg'>:</span></td> <td width='400' valign='top'><span class='m'>$_POST[fra]</span></td> </tr> <tr> <td width='99' valign='top'><span class='mg'><b>E-mail</b></span></td> <td width='1' valign='top'><span class='mg'>:</span></td> <td width='400' valign='top'><span class='m'>$_POST[email]</span></td> </tr> </table> </td> </tr> <tr> <td width='100%' valign='top'><span class='m'>".stripslashes($_POST[besked])."</span></td> </tr> </table> </center> </body> </html>"; $headers = "From: " .$_POST[email]. "<$_POST[email]>\n"; $headers .= "X-Sender: <$_POST[email]>\n"; $headers .= "X-Mailer: PHP\n"; $headers .= "Return-Path: <$_POST[email]>\n"; $headers .= "Content-Type: text/html; charset=iso-8859-1\n"; $headers .= "MIME-Version: 1.0\n"; $message = $message . "<br /><br />Afsendt fra: " . $_SERVER['REMOTE_ADDR']; mail($email, $subject, $message, $headers); mail($email, $subject, $message, $headers); header("Location: ".$PHP_SELF."?status=sendt"); } ?> <html> <head> <link rel='stylesheet' type='text/css' href='css/style.css' /> <script langauge="javascript"> <!-- function checkform() { if (document.form.emne.value == "Emne") { alert ('Feltet "emne" skal udfyldes'); return false; } if (document.form.besked.value == "Besked") { alert ('Feltet "besked" skal udfyldes'); return false; } form.submit() } //--> </script> </head> <body> <div class='understreg'><span class='header'>Mail formular</span></div> <br style='font-size: 5px;' /> <br style='font-size: 5px;' /> <?php if($_GET[status] =="sendt"){ echo" <table border='$tableborder' width='$tablewidth' cellspacing='$tablecellspacing' cellpadding='$tablecellpadding'> <tr> <td width='100%' align='center'><span class='mfont'><b>Mail er nu sendt.</b></span></td> </tr> </table>"; }?> <form method='POST' action='<?=$PHP_SELF;?>' name='form'> <table <?php echo"border='$tableborder' width='$tablewidth' cellspacing='$tablecellspacing' cellpadding='$tablecellpadding'"; ?>> <tr> <td width="72%" valign="top" height="15"> <input type="text" name="emne" value="Emne" onfocus="if(this.value=='Emne')this.value='';" onblur="if(this.value=='')this.value='Emne';" size="45" class='input'></td> </tr> <tr> <td width="72%" valign="top" height="15"><input type="text" name="fra" value="Dit navn" onfocus="if(this.value=='Dit navn')this.value='';" onblur="if(this.value=='')this.value='Dit navn';" size="45" class='input'></td> </tr> <tr> <td width="72%" valign="top" height="15"><input type="text" name="email" value="E-mail" onfocus="if(this.value=='E-mail')this.value='';" onblur="if(this.value=='')this.value='E-mail';" size="45" class='input'><span class='sfont'>*</span></td> </tr> <tr> <td width="72%" valign="top" height="15"> <textarea cols="45" rows="10" onfocus="if(this.value=='Besked')this.value=''" onblur="if(this.value=='')this.value='Besked'" id="text" name="besked">Besked</textarea><span class='sfont'>*</span></td> </tr> <tr> <td width="100%" valign="top" height="14"><span class='sfont'>* = Skal udfyldes.</span><br /><input class="inputsend" type="submit" value="Send" name="send" onclick="checkform()"></td> </tr> </table> </form>
02. november 2004 - 14:00
#7
Sådan du mente?
02. november 2004 - 14:02
#8
Takker for svaret...:P
02. november 2004 - 14:02
#9
Jaw skriv lige et svar, så jeg kan give dig point
02. november 2004 - 14:04
#10
Ja, det var sådan jeg mente - lige på nær, at der ikke er nogen grund til at have linien: mail($email, $subject, $message, $headers); 2 gange. Og selv tak :)
Vi tilbyder markedets bedste kurser inden for webudvikling