I've been trying to fix this script for the past 2 hours and I have no idea what I'm doing wrong. Can you pro Gurus take a look at it and tell me why I'm such a 'tard.
It's pretty simple - 2 files, contact.php and contact.html I had to edit both to accommodate my form. I haven't played arround with PHP for a while so I'm not quite sure what i messed up while I was editing. You simply need to customize the URL and email variables at the beginning of contact.php.
2 Issues here:
1) When I press send, nothing happens?
2) How do I put the same static subject line onto all emails the form creates?
contact.php
<?php
// ------- Contact Page and Email variables -------------------------------------------------------
$valid_ref1="http://site.com/contact.html";
$valid_ref2="http://www.site.com/contact.html";
$replyemail="email@gmail.com";//change to your info
// ------------------------------------------------------------
//clean input in case of header injection attempts!
function clean_input_4email($value, $check_all_patterns = true)
{
$patterns[0] = '/content-type:/';
$patterns[1] = '/to:/';
$patterns[2] = '/cc:/';
$patterns[3] = '/bcc:/';
if ($check_all_patterns)
{
$patterns[4] = '/\r/';
$patterns[5] = '/\n/';
$patterns[6] = '/%0a/';
$patterns[7] = '/%0d/';
}
//NOTE: can use str_ireplace as this is case insensitive but only available on PHP version 5.0.
return preg_replace($patterns, "", strtolower($value));
}
$parpre = clean_input_4email($_POST["parpre"]);
$parnom = clean_input_4email($_POST["parnom"]);
$enfpre = clean_input_4email($_POST["enfpre"]);
$enfnom = clean_input_4email($_POST["enfnom"]);
$age = clean_input_4email($_POST["age"]);
$classe = clean_input_4email($_POST["classe"]);
$tel = clean_input_4email($_POST["tel"]);
$add1 = clean_input_4email($_POST["add1"]);
$cp = clean_input_4email($_POST["cp"]);
$loc = clean_input_4email($_POST["loc"]);
$thesubject = clean_input_4email($_POST["thesubject"]);
$themessage = clean_input_4email($_POST["themessage"], false);
$error_msg='ERREUR SVP CONTACTEZ L'ADMINISTRATEUR.';
$success_sent_msg='<p align="center"><strong> </strong></p>
<p align="center"><strong>Merci pour votre demande.<br>
</strong> Nous vous contacterons sous peu.</p>
<p align="center"> </p>';
$replymessage = "Bonjour $parpre $parnom
Merci pour votre email.
Nous vous contacterons sous peu.
Infos:
--------------------------------------------------
$themessage
--------------------------------------------------
Merci d'avance
Cordialement";
// 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)
{
echo "<script language=\"JavaScript\"><!--\n alert(\"$error_msg\");\n";
echo "top.location.href = \"$valid_ref1\"; \n// --></script>";
exit;
}
$themessage = "Parent: $parpre $parnom \nEnfant: $enfpre $enfnom \nAge: $age \nClasse: $classe \nEmail: $email \nTelephone: $tel \nAdresse: $add1 $add2 \nVille: $loc \nCodePostal: $cp \nMatiere: $mat \nObjectif: $obj \nNombreEnfant $enf_id";
mail("$replyemail",
"$thesubject",
"$themessage",
"From: $email\nReply-To: $email");
mail("$email",
"Receipt: $thesubject",
"$replymessage",
"From: $replyemail\nReply-To: $replyemail");
echo $success_sent_msg;
?>
contact.html
<html>
<head>
<title>Form Mailer</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;}
</style>
</head>
<body>
<form name="phpformmailer" action="contact.php" align="center" method="post">
<div align="center"><center><table bgcolor="#F2F2F2" width="528" cellspacing="6">
<tr>
<td width="159"><strong>Contactez Nous</strong></td>
<td width="349"></td>
</tr>
<tr>
<td align="right" width="159"><small>Sujet*:</small></td>
<td width="349"><font face="Arial"><input class="inputc" size="29" name="thesubject"></font></td>
</tr>
<tr>
<td align="right" width="159"><small>Votre prénom*:</small></td>
<td width="349"><font face="Arial"><input class="inputc" size="29" name="parpre"></font></td>
</tr>
<tr>
<td align="right" width="159"><small>Votre nom*:</small></td>
<td width="349"><font face="Arial"><input class="inputc" size="29" name="parnom"></font></td>
</tr>
<tr>
<td align="right" width="159"><small>Prenom de votre enfant*:</small></td>
<td width="349"><font face="Arial"><input class="inputc" size="29" name="enfpre"></font></td>
</tr>
<tr>
<td align="right" width="159"><small>Nom de votre enfant*:</small></td>
<td width="349"><font face="Arial"><input class="inputc" size="29" name="enfnom"></font></td>
</tr>
<tr>
<td align="right" width="159"><small>Son Age*:</small></td>
<td width="349"><font face="Arial"><input class="inputc" size="29" name="age"></font></td>
</tr>
<tr>
<td align="right" width="159"><small>Sa classe*:</small></td>
<td width="349"><font face="Arial"><input class="inputc" size="29" name="classe"></font></td>
</tr>
<tr>
<td align="right" width="159"><font color="#000080" size="1">*</font><small> Votre e-mail*</small></td>
<td align="left" width="349"><font face="Arial"><input class="inputc" size="29"
name="email"></font></td>
</tr>
<tr align="middle">
<td align="right" width="159"><font color="#000080" size="1">*</font><small> Confirmez Votre e-mail*:</small></td>
<td width="349" align="left"><font face="Arial"><input class="inputc" size="29"
name="email2"></font></td>
</tr>
<tr>
<td align="right" width="159"><small>Telephone*:</small></td>
<td width="349"><font face="Arial"><input class="inputc" size="29" name="tel"></font></td>
</tr>
<tr>
<td align="right" width="159"><small>Addresse Postale*:</small></td>
<td width="349"><font face="Arial"><input class="inputc" size="29" name="adr1"></font></td>
</tr>
<tr>
<td align="right" width="159"><small>.</small></td>
<td width="349"><font face="Arial"><input class="inputc" size="29" name="adr"></font></td>
</tr>
<tr>
<td align="right" width="159"><small>Ville*:</small></td>
<td width="349"><font face="Arial"><input class="inputc" size="29" name="loc"></font></td>
</tr>
<tr>
<td align="right" width="159"><small>Code Postal*:</small></td>
<td width="349"><font face="Arial"><input class="inputc" size="29" name="cp"></font></td>
</tr>
<tr>
<td align="right" width="159"><small>Matiere:</small></td>
<td width="349"><font face="Arial"><input class="inputc" size="29" name="mat"></font></td>
</tr>
<tr>
<td align="right" width="159"><small>Objectif</small></td>
<td width="349"><font face="Arial"><input class="inputc" size="29" name="obj"></font></td>
</tr>
<tr>
<td align="right" width="159"><small>Combien d'enfants chez vous:</small></td>
<td width="349"><font face="Arial"><input class="inputc" size="29" name="mat"></font></td>
</tr>
<tr>
<td width="159"></td>
<td width="349"><script language="JavaScript"><!--
function validateForm()
{
var okSoFar=true
with (document.phpformmailer)
{
var foundAt = email.value.indexOf("@",0)
if (foundAt < 1 && okSoFar)
{
okSoFar = false
alert ("Veuillez écrire une addresse email valide.")
email.focus()
}
var e1 = email.value
var e2 = email2.value
if (!(e1==e2) && okSoFar)
{
okSoFar = false
alert ("Adresses d'email que vous avez écrites sont différentes. Resaisir svp.")
email.focus()
}
if (parpre.value=="" && okSoFar)
{
okSoFar=false
alert("SVP mettez votre prenom.")
parpre.focus()
}
if (parnom.value=="" && okSoFar)
{
okSoFar=false
alert("SVP mettez votre nom.")
parnom.focus()
}
if (enfpre.value=="" && okSoFar)
{
okSoFar=false
alert("SVP mettez le prenom de votre enfant.")
enfpre.focus()
}
if (enfnom.value=="" && okSoFar)
{
okSoFar=false
alert("SVP mettez le nom de votre enfant.")
enfnom.focus()
}
if (age.value=="" && okSoFar)
{
okSoFar=false
alert("SVP mettez l'age de votre enfant.")
age.focus()
}
if (classe.value=="" && okSoFar)
{
okSoFar=false
alert("SVP mettez la classe de vore enfant.")
classe.focus()
}
if (tel.value=="" && okSoFar)
{
okSoFar=false
alert("SVP mettez votre # de téléphone.")
tel.focus()
}
if (add1.value=="" && okSoFar)
{
okSoFar=false
alert("SVP mettez votre # et le nom de votre Rue.")
add1.focus()
}
if (cp.value=="" && okSoFar)
{
okSoFar=false
alert("SVP mettez votre code postal.")
cp.focus()
}
if (loc.value=="" && okSoFar)
{
okSoFar=false
alert("SVP mettez votre location.")
loc.focus()
}
if (okSoFar==true) submit();
}
}
// --></script><input type="button" class="button"
value="Envoyer" name="B1" ONCLICK="javascript:validateForm()"><small> <small>Les champs marqués d'une <strong>astérisque (*) sont obligatoires.</strong></small></small></td>
</tr>
</table>
</center></div>
</form>
</body>
</html>
Who can check my code and explain what I'm doing wrong?
Many many thanks!
🙂