Sugarfree Posted February 7, 2008 Report Share Posted February 7, 2008 (edited) Sveiki... Vēlos ievietot lapā nelielu "kontaktformu", sameklēju, manuprāt, visvienkāršāko variantu, tomēr lieta tāda, ka notestējot un e-pastu saņemot nav garumzīmju. Šeit būs kods: <?php /* Thank you for choosing FormToEmail by FormToEmail.com Version 2.3 December 5th 2007 COPYRIGHT FormToEmail.com 2003 - 2007 SETUP INSTRUCTIONS Step 1: Put the form on your webpage Step 2: Enter your email address and (optional) continue link below Step 3: Upload the files to your webspace Step 1: To put the form on your webpage, copy the code below as it is, and paste it into your webpage: <form action="FormToEmail.php" method="post"> <table border="0" bgcolor="#ececec" cellspacing="5"> <tr><td>Name</td><td><input type="text" size="30" name="name"></td></tr> <tr><td>Email address</td><td><input type="text" size="30" name="email"></td></tr> <tr><td valign="top">Comments</td><td><textarea name="comments" rows="6" cols="30"></textarea></td></tr> <tr><td> </td><td><input type="submit" value="Send"><font face="arial" size="1"> <a href="http://FormToEmail.com">Form Mail</a> by FormToEmail.com</font></td></tr> </table> </form> Step 2: Enter your email address. Enter the email address below to send the contents of the form to. You can enter more than one email address separated by commas, like so: $my_email = "bob@example.com,sales@example.co.uk,jane@example.com"; */ $my_email = "example@example.com"; /* Enter the continue link to offer the user after the form is sent. If you do not change this, your visitor will be given a continue link to your homepage. If you do change it, remove the "/" symbol below and replace with the name of the page to link to, eg: "mypage.htm" or "http://www.elsewhere.com/page.htm" */ $continue = "/"; /* Step 3: Save this file (FormToEmail.php) and upload it together with your webpage containing the form to your webspace. IMPORTANT - The file name is case sensitive! You must save it exactly as it is named above! Do not put this script in your cgi-bin directory (folder) it may not work from there. THAT'S IT, FINISHED! You do not need to make any changes below this line. */ $errors = array(); // Remove $_COOKIE elements from $_REQUEST. if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}} // Check all fields for an email header. function recursive_array_check_header($element_value) { global $set; if(!is_array($element_value)){if(preg_match("/(%0A|%0D|\n+|\r+)(content-type:|to:|cc:|bcc:)/i",$element_value)){$set = 1;}} else { foreach($element_value as $value){if($set){break;} recursive_array_check_header($value);} } } recursive_array_check_header($_REQUEST); if($set){$errors[] = "You cannot send an email header";} unset($set); // Validate email field. if(isset($_REQUEST['email']) && !empty($_REQUEST['email'])) { if(preg_match("/(%0A|%0D|\n+|\r+|:)/i",$_REQUEST['email'])){$errors[] = "Email address may not contain a new line or a colon";} $_REQUEST['email'] = trim($_REQUEST['email']); if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}} } // Check referrer is from same site. if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";} // Check for a blank form. function recursive_array_check_blank($element_value) { global $set; if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}} else { foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);} } } recursive_array_check_blank($_REQUEST); if(!$set){$errors[] = "You cannot send a blank form";} unset($set); // Display any errors and exit if errors exist. if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;} if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");} // Build message. function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");} $message = build_message($_REQUEST); $message = $message . PHP_EOL.PHP_EOL."-- ".PHP_EOL."Thank you for using FormToEmail from http://FormToEmail.com"; $message = stripslashes($message); $subject = "FormToEmail Comments"; $headers = "From: " . $_REQUEST['email']; mail($my_email,$subject,$message,$headers); ?> Cik noprotu, tam varētu būt saistība ar charset? Bet kā to panākt .php failā? Edited February 7, 2008 by Sugarfree Link to comment Share on other sites More sharing options...
Paulinjsh Posted February 7, 2008 Report Share Posted February 7, 2008 (edited) paste.php.lv tad varbūt apskatīsimies. $header mainīgajā ieraksti vēl encodingu, kā to sameklē tepat forumā pēc atslēgas vārda mail vai arī skaties http://lv.php.net/manual/en/function.mail.php Edited February 7, 2008 by Paulinjsh Link to comment Share on other sites More sharing options...
Sugarfree Posted February 7, 2008 Author Report Share Posted February 7, 2008 mēģināju pievienot šādu te rindiņu, bet nekā: $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; Link to comment Share on other sites More sharing options...
Aleksejs Posted February 7, 2008 Report Share Posted February 7, 2008 Atver pasta programmā kādam mailam, kurš atnācis korekti, tā sourci un paskaties visus tos headerus, kā arī apskaties, kā tiek kodētas pašas garumzīmes. Link to comment Share on other sites More sharing options...
Sugarfree Posted February 7, 2008 Author Report Share Posted February 7, 2008 (edited) Atvēru, tur bija rakstīs tas pats - Content-type: text/html; charset=utf-8 Bet nu tik un tā nesaprotu kā viņu ievietot šajā scriptā... izmēģināju entos veidus, nekā... vairākas stundas nosēdēju ar kaut kādu sīku figņu un bez panākumiem. Acīmredzot neizprotu kā tas viss "līmējās" kopā. Turklāt tajā php.net paraugā taču rakstīts: // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; iekopēju tās abas rindiņas, nomainīju uz utf-8, bet... Ko ne tā esmu sapratis? ;/ Mulsina vēl tas, ka pameklējot pa google kaut kādus paraugus, tie ir tik dažādi... Edited February 7, 2008 by Sugarfree Link to comment Share on other sites More sharing options...
Aleksejs Posted February 8, 2008 Report Share Posted February 8, 2008 Nu aizsūti sev testa e-pastu ar subject: ĒŪĪĻĶĢŠĀŽČŅņčžāšģķļīūē un body: ĒŪĪĻĶĢŠĀŽČŅņčžāšģķļīūē Un apskaties, kā izskatās burti ;) Link to comment Share on other sites More sharing options...
Sugarfree Posted February 8, 2008 Author Report Share Posted February 8, 2008 Lūk iznākums: Subject: ÄÅĒÄĒÄģÄļÄĸÅ ÄÅŊÄÅÅÄÅžÄÅĄÄŖġÄŧÄĢÅĢÄ Comments: ÄÅĒÄĒÄģÄļÄĸÅ ÄÅŊÄÅÅÄÅžÄÅĄÄŖġÄŧÄĢÅĢÄ Iekš "message source" encoding vispār neuzrādās Link to comment Share on other sites More sharing options...
andrisp Posted February 8, 2008 Report Share Posted February 8, 2008 Pameklē tepat forumā. Ir runāts par utf8 meilu sūtīšanu. Link to comment Share on other sites More sharing options...
Aleksejs Posted February 8, 2008 Report Share Posted February 8, 2008 Es biju domājis caur normālu pasta klientu (Thunderbird), kuram var uzlikt pareizo kodējumu aizsūti pats sev un tad izpēti sourci. Link to comment Share on other sites More sharing options...
Sugarfree Posted February 8, 2008 Author Report Share Posted February 8, 2008 Ok, sāku visu no jauna, sameklēju vēl vienu scriptu, izskatās tagad šādi: <?php $EmailTo = "paraugs@paraugs.lv"; $Name = $_POST['Name']; $Email = $_POST['Email']; $Phone = $_POST['Phone']; $Message = $_POST['Message']; // The body text of your email $Body = ""; $Body .= "Vards: "; $Body .= $Name; $Body .= " "; $Body .= "e-pasts: "; $Body .= $Email; $Body .= " "; $Body .= "Talrunis: "; $Body .= $Phone; $Body .= " "; $Body .= "Teksts: "; $Body .= $Message; $Body .= " "; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; // command that calls the php mail() function mail($EmailTo, $Subject, $Body, "From: $Email", $headers); ?> Diemžēl pat neizdodas nosūtīt, jo pie nosūtīšanas parādās: Warning: mail() [function.mail]: SAFE MODE Restriction in effect. The fifth parameter is disabled in SAFE MODE. in /var/www/vhosts/paraugs.lv/httpdocs/contact.php on line 33 Iznāk, ka es nemaz nevaru izmantot "$headers" ? Link to comment Share on other sites More sharing options...
andrisp Posted February 8, 2008 Report Share Posted February 8, 2008 Tā sanāk gan. Palasi par safe mode. Link to comment Share on other sites More sharing options...
Paulinjsh Posted February 8, 2008 Report Share Posted February 8, 2008 sūti caur smtp Link to comment Share on other sites More sharing options...
Aleksejs Posted February 8, 2008 Report Share Posted February 8, 2008 Paulinjsh, domā, ka šīs funkcijas iekš SAFE_MODE nebūs aizvērtas? Link to comment Share on other sites More sharing options...
Sugarfree Posted February 8, 2008 Author Report Share Posted February 8, 2008 (edited) sūti caur smtp Gribētu vismaz pamēģināt, tikai vēl, protams, nezinu kā to izdarīt... Savādāk jau sanāk, ka viss vējā... Edited February 8, 2008 by Sugarfree Link to comment Share on other sites More sharing options...
Paulinjsh Posted February 8, 2008 Report Share Posted February 8, 2008 nu nezinu, bet mēģināt var http://lv.php.net/fsockopen Link to comment Share on other sites More sharing options...
Recommended Posts