PHP FormMail Generator Problem

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • PHP FormMail Generator Problem

    Also ich will auf meine Seite einen Formmailer einbauen und benutze dazu "PHP FormMail Generator V1.0"

    der coder der Kontakt.php sieht so aus:

    Quellcode

    1. <?php include_once( "20070515-330d.lib.php" ); ?>
    2. <?php
    3. if( !$isHideForm ):
    4. global $sErr ;
    5. if( $sErr ) print "<br><a name='error'></a><center><font class='form_error' >$sErr</font></center><br>";
    6. $starColor = $sErr ? "#ff0000" : "#000000";
    7. $style=" class='form_text' ";
    8. ?>
    9. <form name="frmFormMail" action="kontakt.php" method='post' enctype='multipart/form-data'>
    10. <input type='hidden' name='formmail_submit' value='Y'>
    11. <input type='hidden' name='esh_formmail_recipient' value="emailadresse1, emailadresse2">
    12. <input type='hidden' name='esh_formmail_subject' value="Crewpage / Kontaktformular">
    13. <input type='hidden' name='esh_formmail_cc' value="">
    14. <input type='hidden' name='esh_formmail_bcc' value="">
    15. <input type='hidden' name='esh_formmail_return_subject' value="Underground Selection Crew Kontakt">
    16. <input type='hidden' name='esh_formmail_return_msg' value="Vielen Dank für ihre Nachricht, wir werden uns
    17. schnellstmöglich an die bearbeitung machen!
    18. Greetz
    19. Underground Selection Team">
    20. <input type='hidden' name='esh_formmail_mail_and_file' value="">
    21. <input type='hidden' name='esh_formmail_charset' value="">
    22. <table cellspacing='16' cellpadding='0' border='0' >
    23. <tr>
    24. <td class="form_field" valign='top' align='right'>Ihre Name </td><td width='10' aligh='right' valign='top'> <font size='2' color='#ff0000'>*</font> </td>
    25. <td class="form_text">
    26. <input type="text" name="Ihre_Name" value="<?php print HtmlSpecialChars( $HTTP_POST_VARS[ "Ihre_Name" ] ); ?>" class='text_box'>
    27. </td>
    28. </tr>
    29. <tr>
    30. <td class="form_field" valign='top' align='right'>Ihre Email Adresse? </td><td width='10' aligh='right' valign='top'> <font size='2' color='#ff0000'>*</font> </td>
    31. <td class="form_text">
    32. <input type="sender's email" name="Ihre_Email_Adresse" value="<?php print HtmlSpecialChars( $HTTP_POST_VARS[ "Ihre_Email_Adresse" ] ); ?>" class='text_box'>
    33. </td>
    34. </tr>
    35. <tr>
    36. <td class="form_field" valign='top' align='right'>Ihre Homepage </td><td width='10' aligh='right' valign='top'></td>
    37. <td class="form_text">
    38. <input type="text" name="Ihre_Homepage" value="<?php print HtmlSpecialChars( $HTTP_POST_VARS[ "Ihre_Homepage" ] ); ?>" class='text_box'>
    39. </td>
    40. </tr>
    41. <tr>
    42. <td class="form_field" valign='top' align='right'>MSN / ICQ ? </td><td width='10' aligh='right' valign='top'></td>
    43. <td class="form_text">
    44. <input type="text" name="MSN_ICQ" value="<?php print HtmlSpecialChars( $HTTP_POST_VARS[ "MSN_ICQ" ] ); ?>" class='text_box'>
    45. </td>
    46. </tr>
    47. <tr>
    48. <td class="form_field" valign='top' align='right'>Ihre Nachricht: </td><td width='10' aligh='right' valign='top'> <font size='2' color='#ff0000'>*</font> </td>
    49. <td class="form_text">
    50. <textarea name="Ihre_Nachricht" rows=4 cols=25 ><?php print HtmlSpecialChars( $HTTP_POST_VARS[ "Ihre_Nachricht" ] ); ?></textarea>
    51. </td>
    52. </tr>
    53. <tr><td colspan=3 align='center'><input type='submit' value='Submit'> &nbsp;&nbsp; <input type='button' value='Cancel' onclick="location.href='/';"></td></tr>
    54. </table>
    55. </form>
    56. <?php
    57. if( $sErr ) print "<script language='javascript' type='text/javascript'>location.href='#error';</script>";;;
    58. else: //!$isHideForm
    59. print( "<br><br><hr><center><b>Your form has been sent. Thank you.</b><br><br><input type='button' value='Home' onclick=\"location.href='/';\"></center><br><br>" );
    60. endif; //!$isHideForm
    61. ?>
    Alles anzeigen



    und der der include datei "20070515-330d.lib.php" so:

    Quellcode

    1. <?
    2. define( "ADMIN_MAIL", "s6software@users.sourceforge.net" ); // bug report email
    3. define( "HOST_NAME", getEnv( "HTTP_HOST" ) );
    4. define( "PHP_SELF", getEnv( "SCRIPT_NAME" ) );
    5. define( "ERR_MISSING", "Missing required field : " );
    6. define( "ERR_EMAIL", "Please type in a valid e-mail address : " );
    7. define( "ERR_CREDIT_CARD_NUMBER", "Please check the credit card number : " );
    8. define( "ERR_CREDIT_CARD_EXPIRED", "Please check the credit card expiry date : " );
    9. define( "ERR_SELECT_UPLOAD", "Please select upload file : " );
    10. error_reporting( E_ERROR | E_WARNING | E_PARSE );
    11. ?><?php
    12. // --- Array of Form Elements ---
    13. $form_mail[] = array( "name" => "Ihre_Name", "text" => "Ihre Name", "type" => "text", "required" => "Required" ) ;
    14. $form_mail[] = array( "name" => "Ihre_Email_Adresse", "text" => "Ihre Email Adresse?", "type" => "sender's email", "required" => "Required" ) ;
    15. $form_mail[] = array( "name" => "Ihre_Homepage", "text" => "Ihre Homepage", "type" => "text", "required" => "" ) ;
    16. $form_mail[] = array( "name" => "MSN_ICQ", "text" => "MSN / ICQ ?", "type" => "text", "required" => "" ) ;
    17. $form_mail[] = array( "name" => "Ihre_Nachricht", "text" => "Ihre Nachricht:", "type" => "textarea", "required" => "Required" ) ;
    18. // -- Detech Submit & SendMail --
    19. $isHideForm = false;
    20. if( $HTTP_POST_VARS["formmail_submit"] ){
    21. $sErr = checkPass();
    22. if( ! $sErr ){
    23. sendFormMail( $form_mail, "") ;
    24. $isHideForm = true;
    25. $redirect = "";
    26. if( strlen(trim($redirect)) ):
    27. header( "Location:$redirect" );
    28. exit;
    29. endif;
    30. }
    31. }
    32. ?>
    33. <?
    34. // ===============================================
    35. function sendFormMail( $form_mail, $sFileName = "" )
    36. {
    37. global $HTTP_POST_VARS ;
    38. $to = $HTTP_POST_VARS["esh_formmail_recipient"]; // I don't detect spam at this moment. it's to do list.
    39. $from = "online.submit@" . HOST_NAME ;
    40. $subject = $HTTP_POST_VARS["esh_formmail_subject"];
    41. // first stage keep it simple:
    42. $sWhatToDo = $sFileName ? "mailandfile" : "" ; //$HTTP_POST_VARS["esh_formmail_mail_and_file"];
    43. //$sFileName = $HTTP_POST_VARS["esh_formmail_save_record_file"];
    44. $cc = $HTTP_POST_VARS["esh_formmail_cc"];
    45. $bcc = $HTTP_POST_VARS["esh_formmail_bcc"];
    46. $charset = $HTTP_POST_VARS["esh_formmail_charset"];
    47. for( $i = 0; $i < count( $form_mail ); $i ++ ){
    48. $value = trim( $HTTP_POST_VARS[ $form_mail[ $i ][ "name" ] ] );
    49. $content .= $form_mail[ $i ][ "text" ] . " \t : " . $value ."\n";
    50. $line .= remove_newline( $value ) . "\t" ;
    51. if( strtolower("Sender's email") == strtolower($form_mail[ $i ][ "type" ]) ) {
    52. //print "Type:[" . $form_mail[ $i ][ "type" ] . "] $value <br>\n";
    53. $from = $value ;
    54. }
    55. };
    56. $content .= "\n\nIP:" . getEnv( "REMOTE_ADDR" );
    57. switch( strtolower($sWhatToDo) ){
    58. case "mailandfile" :
    59. mailAttachments( $to , $subject , $content, $from, $charset, $cc , $bcc ) ;
    60. if( ! appendToFile( $sFileName, $line ) )
    61. mailReport( $content . "\n\nWrite Form Mail to File Fail." );
    62. break;
    63. case "fileonly" :
    64. if( ! appendToFile( $sFileName, $line ) )
    65. mailReport( $content . "\n\nWrite Form Mail to File Fail.", $from );
    66. break;
    67. default :
    68. mailAttachments( $to , $subject , $content, $from, $charset, $cc , $bcc ) ;
    69. }
    70. mailAutoResponse( $from ) ;
    71. }
    72. //------------------------------------------------------------------------------------------
    73. function mailAutoResponse( $to ){
    74. global $HTTP_POST_VARS ;
    75. $subject = $HTTP_POST_VARS["esh_formmail_return_subject"];
    76. $responseMsg = $HTTP_POST_VARS["esh_formmail_return_msg"];
    77. if( $to && $responseMsg )
    78. mail( $to, $subject, $responseMsg, "From: " . $HTTP_POST_VARS["esh_formmail_recipient"] );
    79. }
    80. //------------------------------------------------------------------------------------------
    81. function mailReport( $content = "", $from = "" ){
    82. mail( ADMIN_MAIL, "Error@" . HOST_NAME . PHP_SELF, $content, "From:$from" );
    83. }
    84. //------------------------------------------------------------------------------------------
    85. function remove_newline( $str = "" ){
    86. $newliner = "<!--esh_newline-->" ; // replace \r\n with $newliner ;
    87. $newtaber = "<!--esh_newtaber-->" ; // replace \t with $newtaber ;
    88. $str = ereg_replace( "\t", $newtaber, $str );
    89. $str = ereg_replace( "\r\n", $newliner, $str );
    90. return ereg_replace( "\n", $newliner, $str );
    91. }
    92. //------------------------------------------------------------------------------------------
    93. function checkPass()
    94. {
    95. global $form_mail ;
    96. global $HTTP_POST_VARS ;
    97. global $HTTP_POST_FILES ;
    98. for( $i = 0; $i < count( $form_mail ); $i ++ ){
    99. $type = strtolower( $form_mail[ $i ][ "type" ] );
    100. $value = trim( $HTTP_POST_VARS[ $form_mail[ $i ][ "name" ] ] );
    101. $required = $form_mail[ $i ][ "required" ] ;
    102. $text = stripslashes( $form_mail[ $i ][ "text" ] );
    103. // simple check the field has something keyed in.
    104. if( !strlen($value) && ( $required == "Required" ) && $type != "attachment" )
    105. return ERR_MISSING . $text ;
    106. // verify the special case
    107. if(
    108. ( strlen($value) || $type == "attachment" )
    109. && $required == "Required"
    110. ):
    111. switch( $type ){
    112. case strtolower("Sender's Name") :
    113. break;
    114. case strtolower("Generic email"):
    115. case strtolower("Sender's email"):
    116. if( ! formIsEMail($value) ) return ERR_EMAIL . $text ;
    117. break;
    118. case "text" :
    119. break;
    120. case "textarea" :
    121. break;
    122. case "checkbox" :
    123. case "radio" :
    124. break;
    125. case "select" :
    126. break;
    127. case "attachment" :
    128. $upload_file = $HTTP_POST_FILES[ $form_mail[ $i ]["name"] ][ "tmp_name" ] ;
    129. if( ! is_uploaded_file($upload_file) )
    130. return ERR_SELECT_UPLOAD . $text;
    131. break;
    132. case strtolower("Date(MM-DD-YYYY)"):
    133. break;
    134. case strtolower("Date(MM-YYYY)"):
    135. break;
    136. case strtolower("CreditCard(MM-YYYY)"):
    137. if( $value < date("Y-m") ) return ERR_CREDIT_CARD_EXPIRED . $text;
    138. break;
    139. case strtolower("CreditCard#"):
    140. if( !formIsCreditNumber( $value ) ) return ERR_CREDIT_CARD_NUMBER . $text ;
    141. break;
    142. case strtolower("Time(HH:MM:SS)"):
    143. break;
    144. case strtolower("Time(HH:MM)"):
    145. break;
    146. default :
    147. //return $sErrRequired . $form_mail[ $i ][ "text" ];
    148. } // switch
    149. endif;
    150. } // for
    151. return "" ;
    152. }
    153. //------------------------------------------------------------------------------------------
    154. function formSelected( $var, $val )
    155. {
    156. echo ( $var == $val ) ? "selected" : "";
    157. }
    158. //------------------------------------------------------------------------------------------
    159. function formChecked( $var, $val )
    160. {
    161. echo ( $var == $val ) ? "checked" : "";
    162. }
    163. //------------------------------------------------------------------------------------------
    164. function formIsEMail( $email ){
    165. return ereg( "^(.+)@(.+)\\.(.+)$", $email );
    166. }
    167. //------------------------------------------------------------------------------------------
    168. function selectList( $name, $selectedValue, $start, $end, $prompt = "-Select-", $style = "" )
    169. {
    170. $tab = "\t" ;
    171. print "<select name=\"$name\" $style>\n" ;
    172. print $tab . "<option value=''>$prompt</option>\n" ;
    173. $nLen = strlen( "$end" ) ;
    174. $prefix_zero = str_repeat( "0", $nLen );
    175. for( $i = $start; $i <= $end ; $i ++ ){
    176. $stri = substr( $prefix_zero . $i, strlen($prefix_zero . $i)-$nLen, $nLen );
    177. $selected = ( $stri == $selectedValue ) ? " selected " : "" ;
    178. print $tab . "<option value=\"$stri\" $selected >$stri</option>\n" ;
    179. }
    180. print "</select>\n\n" ;
    181. }
    182. //------------------------------------------------------------------------------------------
    183. // something like CreditCard.pm in perl CPAN
    184. function formIsCreditNumber( $number ) {
    185. $tmp = $number;
    186. $number = preg_replace( "/[^0-9]/", "", $tmp );
    187. if ( preg_match( "/[^\d\s]/", $number ) ) return 0;
    188. if ( strlen($number) < 13 && 0+$number ) return 0;
    189. for ($i = 0; $i < strlen($number) - 1; $i++) {
    190. $weight = substr($number, -1 * ($i + 2), 1) * (2 - ($i % 2));
    191. $sum += (($weight < 10) ? $weight : ($weight - 9));
    192. }
    193. if ( substr($number, -1) == (10 - $sum % 10) % 10 ) return $number;
    194. return $number;
    195. }
    196. // -------------------------- Begin Mail Attachment Functions -----------------------------------------------------------------
    197. function mailAttachments( $to = "" , $subject = "" , $message = "" , $from = "support@lynx.net" , $charset = "iso-8859-1", $cc = "" , $bcc = "" ){
    198. global $HTTP_POST_FILES ;
    199. if( ! strlen( trim( $to ) ) ) return "Missing \"To\" Field." ;
    200. $boundary = "====_My_PHP_Form_Generator_" . md5( uniqid( srand( time() ) ) ) . "====";
    201. // setup mail header infomation
    202. $headers = "From: $from\r\n";
    203. if ($cc) $headers .= "CC: $cc\r\n";
    204. if ($bcc) $headers .= "BCC: $bcc\r\n";
    205. $plainHeaders = $headers ; // for no attachments header
    206. $headers .= "MIME-Version: 1.0\nContent-type: multipart/mixed;\n\tboundary=\"$boundary\"\n";
    207. $txtMsg = "\nThis is a multi-part message in MIME format.\n" .
    208. "\n--$boundary\n" .
    209. "Content-Type: text/plain;\n\tcharset=\"$charset\"\n\n" . $message . "\n";
    210. //create mulitipart attachments boundary
    211. $sError = "" ;
    212. $nFound = 0;
    213. foreach( $HTTP_POST_FILES as $aFile ){
    214. $sFileName = $aFile[ "tmp_name" ] ;
    215. $sFileRealName = $aFile[ "name" ] ;
    216. if( is_file( $sFileName ) ):
    217. if( $fp = fopen( $sFileName, "rb" ) ) :
    218. $sContent = fread( $fp, filesize( $sFileName ) );
    219. $sFName = basename( $sFileRealName ) ;
    220. $sMIME = getMIMEType( $sFName ) ;
    221. $bPlainText = ( $sMIME == "text/plain" ) ;
    222. if( $bPlainText ) :
    223. $encoding = "" ;
    224. else:
    225. $encoding = "Content-Transfer-Encoding: base64\n";
    226. $sContent = chunk_split( base64_encode( $sContent ) );
    227. endif;
    228. $sEncodeBody .= "\n--$boundary\n" .
    229. "Content-Type: $sMIME;\n" .
    230. "\tname=\"$sFName\"\n" .
    231. $encoding .
    232. "Content-Disposition: attachment;\n" .
    233. "\tfilename=\"$sFName\"\n\n" .
    234. $sContent . "\n" ;
    235. $nFound ++;
    236. else:
    237. $sError .= "<br>File $sFileName can not open.\n" ;
    238. endif; // if( $fp = fopen( $sFileName, "rb" ) ) :
    239. else:
    240. $sError .= "<br>File $sFileName doesn't exist.\n" ;
    241. endif; //if( file_exists( $sFileName ) ):
    242. }; // end foreach
    243. $sEncodeBody .= "\n\n--$boundary--" ;
    244. $sSource = $txtMsg . $sEncodeBody ;
    245. $nFound ? mail( $to, $subject, $sSource, $headers )
    246. : mail( $to, $subject, $message, $plainHeaders );
    247. return $sError ;
    248. }
    249. /* ---------------------------------------------------------------------------------------------------
    250. Parameters: $sFileName
    251. Return :
    252. 1. "" : no extendsion name, or sFileName is empty
    253. 2. string: MIME Type name of array aMimeType's definition.
    254. ---------------------------------------------------------------------------------------------------*/
    255. function getMIMEType( $sFileName = "" ) {
    256. $sFileName = strtolower( trim( $sFileName ) );
    257. if( ! strlen( $sFileName ) ) return "";
    258. $aMimeType = array(
    259. "txt" => "text/plain" ,
    260. "pdf" => "application/pdf" ,
    261. "zip" => "application/x-compressed" ,
    262. "html" => "text/html" ,
    263. "htm" => "text/html" ,
    264. "avi" => "video/avi" ,
    265. "mpg" => "video/mpeg " ,
    266. "wav" => "audio/wav" ,
    267. "jpg" => "image/jpeg " ,
    268. "gif" => "image/gif" ,
    269. "tif" => "image/tiff " ,
    270. "png" => "image/x-png" ,
    271. "bmp" => "image/bmp"
    272. );
    273. $aFile = split( "\.", basename( $sFileName ) ) ;
    274. $nDiminson = count( $aFile ) ;
    275. $sExt = $aFile[ $nDiminson - 1 ] ; // get last part: like ".tar.zip", return "zip"
    276. return ( $nDiminson > 1 ) ? $aMimeType[ $sExt ] : "";
    277. }
    278. // -------------------------- End Mail Attachment Functions -----------------------------------------------------------------
    279. //------------------------------------------------------------------------------------------
    280. function appendToFile( $sFileName = "", $line = "" ){
    281. if( !$sFileName || !$line ) return 0;
    282. $hFile = fopen( "$sFileName", "a+w" );
    283. $nBytes = 0;
    284. if( $hFile ){
    285. $nBytes = fputs( $hFile , trim($line)."\r\n" );
    286. fclose( $hFile );
    287. };
    288. return $nBytes ;
    289. }
    290. ?>
    Alles anzeigen



    Irgendwas funktioniert da nicht, kann das sein das es mit Ajax zusammen hängt ?
    und es vllt die Zeichenkodierung ist? wie schaff ich mir da abhilfe?
    zu sehn ist das ganze auf www.underground-selection-crew.com
  • "d0nUt" schrieb:

    kontakt.php klappt doch.
    => http://www.underground-selection-crew.com/inhalt/kontakt/kontakt.php

    Ich nehme an du arbeitest in der func.php (aufgerufen in der ajax.js) mit file_get_contents. Das geht natürlich nicht, da php so nicht geparst wird.


    hm mist das hab ich mir gedacht X( hat vllt jemand ne möglichkeit was ich da am besten machen könnte ?
  • Entweder du machst in der func.php ein switch/case mit includes statt file_get_content.
    Oder du machst es direkt in der JavaScript Datei mit switch/case

    Aber mal vorab.. wenn du auf submit klickst ist klar, dass du auf kontakt.php geleitet wirst, oder?
    Wenn du die ohne Änderungen am Script die volle Funktionalität in einem Teilbereich der Seite haben willst, musst du auf Frames zurückgreifen.