Jump to content
php.lv forumi

Klientu forma


RWS

Recommended Posts

Sveiciens visiem!

 

Padalījos ar kodu ko atradu (ilgi vajadzēja lai tiktu klāt pie šī). Pats pārbaudīju un strādā kā puķīte. Ir viena nianse, ka sakropļo Latviešu burtus, bet domāju, ka zinātājs jau pamainīs nepieciešamās rindiņas un glīta forma gatava.

 

Pielikumā ir arī pamācība kā lietot, tā kā domāju, ka ikvienam izdosies pievienot savai lapai, jo man izdevās (lai arī no php praktiski neko nezinu :) ). Abi faili ir jāuzliek uz servera, un aiziet!!!

 

 

Good luck!

phpFormMailer_working.zip

Edited by RWS
Link to comment
Share on other sites

Леши, Tu saki ka šo tavu kodu vajadzētu iepeistot php failā pašā augā?

Tūliņ noprovēšu..

 

EDIT: Failā contact-process.php nemaz nav tāda <head> sadaļa! Kur tad peistot?

Edited by RWS
Link to comment
Share on other sites

Iekopēju contact-process.php failā pašā augšā pirmā rindiņā pirms

<?php

, bet nav izmaiņas.

 

Piezīme visiem, kas lietos šo kodu... Epasts tiek nosūtīts gan uz norādīto adresi, gan arī cilvēkam, kas to sūta. Taču es piefiksēju, ka uz gmail man atnāk epasts, bet uz inbox nenāk. Tādēļ esiet uzmanīgi :)

Link to comment
Share on other sites

Ja <head> nav, kur tad likt?

 

Es, piemēram, inbox.lv meilus skatos ar outlook, un Junk meilā nav. Pačekoju arī paša inbox.lv surogātpastu - nav. Tā kā nu interesanti, līdz galam lietojams šis kods tomēr nav, bet nu uz savu epastu ziņa atnāk, tā ka tas ir pluss! :)

 

Zemāk ir redzams viss kods, kas atrodams contact_process.php failā:

<?php
// ------- three variables you MUST change below  -------------------------------------------------------
$replyemail="[email protected]"; //change to your email address
$valid_ref1="http://domain.lv/contact.html"; //chamge to your domain name
$valid_ref2="http://www.domain.lv/contact.html"; //chamge to your domain name

// -------- No changes required below here -------------------------------------------------------------
//
// email variable not set - load $valid_ref1 page
if (!isset($_POST['email']))
{
echo "<script language=\"JavaScript\"><!--\n ";
echo "top.location.href = \"$valid_ref1\"; \n// --></script>";
exit;
}
$ref_page=$_SERVER["HTTP_REFERER"];
$valid_referrer=0;
if($ref_page==$valid_ref1) $valid_referrer=1;
elseif($ref_page==$valid_ref2) $valid_referrer=1;
if((!$valid_referrer) OR ($_POST["block_spam_bots"]!=12))//you can change this but remember to change it in the contact form too
{
echo '<h2>ERROR - not sent.';
if (file_exists("debug.flag")) echo '<hr>"$valid_ref1" and "$valid_ref2" are incorrect within the file:<br>
                                     contact_process.php <br><br>On your system these should be set to: <blockquote>
                                                                         $valid_ref1="'.str_replace("www.","",$ref_page).'"; <br>
                                                                         $valid_ref2="'.$ref_page.'";
                                                                         </blockquote></h2>Copy and paste the two lines above
                                                                         into the file: contact_process.php <br> (replacing the existing variables and settings)';
exit;
}

//check user input for possible header injection attempts!
function is_forbidden($str,$check_all_patterns = true)
{
$patterns[0] = '/content-type:/';
$patterns[1] = '/mime-version/';
$patterns[2] = '/multipart/';
$patterns[3] = '/Content-Transfer-Encoding/';
$patterns[4] = '/to:/';
$patterns[5] = '/cc:/';
$patterns[6] = '/bcc:/';
$forbidden = 0;
for ($i=0; $i<count($patterns); $i++)
 {
  $forbidden = preg_match($patterns[$i], strtolower($str));
  if ($forbidden) break;
 }
//check for line breaks if checking all patterns
if ($check_all_patterns AND !$forbidden) $forbidden = preg_match("/(%0a|%0d|\\n+|\\r+)/i", $str);
if ($forbidden)
{
 echo "<font color=red><center><h3>STOP! Message not sent.</font></h3><br><b>
       The text you entered is forbidden, it includes one or more of the following:
       <br><textarea rows=9 cols=25>";
 foreach ($patterns as $key => $value) echo trim($value,"/")."\n";
 echo "\\n\n\\r</textarea><br>Click back on your browser, remove the above characters and try again.
       </b><br><br><br><br>Thankfully protected by phpFormMailer freely available from:
       <a href=\"http://thedemosite.co.uk/phpformmailer/\">http://thedemosite.co.uk/phpformmailer/</a>";
 exit();
}
}

foreach ($_REQUEST as $key => $value) //check all input
{
if ($key == "themessage") is_forbidden($value, false); //check input except for line breaks
else is_forbidden($value);//check all
}

$name = $_POST["name"];
$email = $_POST["email"];
$thesubject = $_POST["thesubject"];
//$themessage = $_POST["themessage"];
//$themessage = utf8($_POST["themessage"]);
$themessage = $_POST["themessage"];

$success_sent_msg='<p align="center"><strong> </strong></p>
                  <p align="center"><strong>Your message has been successfully sent to us<br>
                  </strong> and we will reply as soon as possible.</p>
                  <p align="center">A copy of your query has been sent to you.</p>
                  <p align="center">Thank you for contacting us.</p>';

$replymessage = "Hi $name

Thank you for your email.

We will endeavour to reply to you shortly.

Please DO NOT reply to this email.

Below is a copy of the message you submitted:
--------------------------------------------------
Subject: $thesubject
Query:
$themessage
--------------------------------------------------

Thank you";

$themessage = "name: $name \nQuery: $themessage";
mail("$replyemail",
    "$thesubject",
    "$themessage",
    "From: $email\nReply-To: $email");
mail("$email",
    "Receipt: $thesubject",
    "$replymessage",
    "From: $replyemail\nReply-To: $replyemail");
echo $success_sent_msg;
?>

Edited by RWS
Link to comment
Share on other sites

Otrā failā contact.html jau bija kaut kas līdzīgs Tavam kodam, to nomainīju pret Tavu. Rezultāts - epastā saņēmu šādu tekstu "Ä« Å Ä". Vai ir vēl kādas idejas?

 

<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type">
<!--<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
-->
<title>Contact Us</title>
<style>
BODY{color:#000000; font-size: 8pt; font-family: Verdana}
.button {background-color: rgb(128,128,128); color:#ffffff; font-size: 8pt;}
.inputc {font-size: 8pt;}
.style3 {font-size: xx-small}
</style>
</head>

<body>

<form name="phpformmailer" action="contact_process.php" align="center" method="post">
 <div align="center"><center><table bgcolor="#F2F2F2" width="742" cellspacing="6">
   <tr>
     <td width="162"><strong>Contact Us</strong></td>
</tr>
   <tr>
     <td align="right" width="162"><small>Your name:</small></td>
     <td width="556"><font face="Arial">
     <input class="inputc" size="50" name="name">
     <input type="hidden" name="block_spam_bots" value="1">
     </font></td>
   </tr>
   <tr>
     <td align="right" width="162"><font color="#000080" size="1">*</font><small> Your email
     address:</small></td>
     <td align="left" width="556"><font face="Arial"><input class="inputc" size="50"
     name="email">
     </font></td>
   </tr>
   <tr align="middle">
     <td align="right" width="162"><font color="#000080" size="1">*</font><small> Confirm email
     address:</small></td>
     <td width="556" align="left"><font face="Arial"><input class="inputc" size="50"
     name="email2">
     </font></td>
   </tr>
   <tr>
     <td align="right" width="162"><font color="#000080" size="1">*</font><small> Subject:</small></td>
     <td width="556"><font face="Arial"><input class="inputc" size="60" name="thesubject">
     </font></td>
   </tr>
   <tr>
     <td align="right" width="162"> 
       <p><font color="#000080" size="1">*</font><small> Your
     request or query:</small></td>
     <td width="556"><textarea style="FONT-SIZE: 10pt" name="themessage" rows="7" cols="60"></textarea>
       <a href="http://thedemosite.co.uk/phpformmailer/"  title="phpFormMailer - easy to use and setup PHP form mailer"> </a></td>
   </tr>
   <tr>
     <td width="162"></td>
     <td width="556"><p>
       <input type="button" class="button"
     value="Send" name="B1" ONCLICK="javascript:validateForm()">
         <small> <small>You must fill in
       the fields marked with a *</p>
       </td>
   </tr>
 </table>
     <p> </p>
     <p> </p>
     <p> </p>
     <p> </p>
     <p> </p>
</center></div>
</form>

<script language="JavaScript"><!--
function validateForm() 
{
var okSoFar=true
with (document.phpformmailer)
{
 var foundAt = email.value.indexOf("@",0)
 if (foundAt < 1 && okSoFar)
 {
   okSoFar = false
   alert ("Please enter a valid email address.")
   email.focus()
 }
 var e1 = email.value
 var e2 = email2.value
 if (!(e1==e2) && okSoFar)
 {
   okSoFar = false
   alert ("Email addresses you entered do not match.  Please re-enter.")
   email.focus()
 }
 if (thesubject.value=="" && okSoFar)
 {
   okSoFar=false
   alert("Please enter the subject.")
   thesubject.focus()
 }
 if (themessage.value=="" && okSoFar)
 {
   okSoFar=false
   alert("Please enter the details for your enquiry.")
   themessage.focus()
 }
 if (okSoFar==true)  
 {
  block_spam_bots.value=4*3;//spam bots currently can not read JavaScript, if could then they'd fail the maths!
  submit();                  // do check for updatea often at:  www.TheDemoSite.co.uk 
 } 
}
}
// --></script>
</body>
</html>

Edited by RWS
Link to comment
Share on other sites

Vēlos visus draugus informēt, ka pateicoties Леший risinājumam ir jāpapildina/ jāpamaina iepriekš publicētais kods uz zemāk esošo. Pats esmu pārbaudījis un teksti strādā kā pieklājas.

 

Paturiet prātā, ka joprojām, ja sūtītāja adrese ir inbox.lv, tad sūtītājs epasta kopiju nesaņem nedz "spam", nedz "junk" nedz arī kādā citā mapē. Ar gmail strādā lieliski, citus neesmu mēģinājis, tā kā tas paliek jūsu pašu ziņā. :)

 

Veiksmi darbos!

 

$themessage = "Name: $name \nMessage: $themessage";
mail("$replyemail",
    "$thesubject",
    "$themessage",
    "From: $email\nReply-To: $email\r\nContent-type: text/plain; charset=UTF-8\r\n");
mail("$email",
    "Receipt: $thesubject",
    "$replymessage",
    "From: $replyemail\nReply-To: $replyemail\r\nContent-type: text/plain; charset=UTF-8\r\n");
echo $success_sent_msg;

Edited by RWS
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...