|
Farriel (m)
|
Have got this silly problem with a PHP form to mail script. I'm currently working on this site, and on the contact page, have got this form http://www.uciko.com/aboutus/contact.htm The problem is, upon filling the form and hitting the submit button, I do get the mail from the form, but without the entries filled. Was wondering if anyone could look at the code and help; <?php
$MailTo = "farriel@gmail.com"; $Body = "My name is $T1 <br> My phone number is $T2 <br> My Fax number is $T3 <br> My email address is $T4 <br> My company Name is $T5 <br> My company phone number is $T6 <br> My company fax number is $T7 <br> My company email address is $T8 <br> This project is classified as $D1 <br> <P> <b>Project Description:</b> $S1 <br> We intend spending about $D2$T9 on this project."; $Subject = "ATTN: New Comment from the web"; $MailFrom = "$T1 <$T2>";
$headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "From: $MailFrom";
if ($MailTo) { if (mail($MailTo, $Subject, $Body, $headers)) {} }
$MailTo2 = "farriel@gmail.com"; $Body2 = "$Body"; $Subject2 = "$Subject"; $MailFrom2 = "$T1 <$T2>";
$headers2 = "MIME-Version: 1.0\r\n"; $headers2 .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers2 .= "From: $MailFrom2";
if ($MailTo2) { if (mail($MailTo2, $Subject2, $Body2, $headers2)) {} }
/* Redirect browser */
$Url = "Location: http://www.uciko.com/aboutus/confirmation.php";
header($Url);
/* Make sure that code below does not get executed when we redirect. */
exit(); ?>This is what is between me and a formal completion of the project.
|
|
|
|
|
|
kazey (m)
|
hahaa you didnt define the values for the form name strings in the form you are using. Besides where is the form? My name is $T1 My phone number is $T2 My Fax number is $T3 My email address is $T4 My company Name is $T5 My company phone number is $T6 My company fax number is $T7 My company email address is $T8 This project is classified as $D1 Project Description: $S1 We intend spending about on this project. $D2$T9 etc and change this to single ' not "" $MailTo2 = ' farriel@gmail.com'; $Body2 = '$Body'; $Subject2 = '$Subject'; $MailFrom2 = '$T1 <$T2>';
|
|
|
|
|
|
sbucareer (f)
|
Is the page not suppose to be saved as a script file i.e. contact.php rather to contact.htm?
You can use this free send a friend code
|
|
|
|
|
|
kazey (m)
|
His code seems to be an action page, but without the form you cant really tell where the problem is. I ran the code on my server, works but of course doesnt show the value of the strings. Thats why I asked for the form.
|
|
|
|
|
|
skima (m)
|
when u need the value from a variable use double quote. so with his quote i think he's right. The code was developed with register global on. But On the server on which u runs it, register global is off. <?php /* I will advise u follow name conventiona when coding dats dim email's variable has $email and company as $company */ //lets dim our variables $T1=$_POST['T1']; $T2=$_POST['T2']; $T3=$_POST['T3']; $T4=$_POST['T4']; $T5=$_POST['T5']; $T6=$_POST['T6']; $T7=$_POST['T7']; $T8=$_POST['T8']; $T9=$_POST['T9']; $D1=$_POST['D1']; $D2=$_POST['D2']; $S1=$_POST['S1']; $MailTo = " farriel@gmail.com"; $Body = "My name is $T1 <br> My phone number is $T2 <br> My Fax number is $T3 <br> My email address is $T4 <br> My company Name is $T5 <br> My company phone number is $T6 <br> My company fax number is $T7 <br> My company email address is $T8 <br> This project is classified as $D1 <br> <P> <b>Project Description:</b> $S1 <br> We intend spending about $D2$T9 on this project."; $Subject = "ATTN: New Comment from the web"; $MailFrom = "$T1 <$T2>"; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "From: $MailFrom"; if ($MailTo) { if (mail($MailTo, $Subject, $Body, $headers)) { } } $MailTo2 = " farriel@gmail.com"; $Body2 = "$Body"; $Subject2 = "$Subject"; $MailFrom2 = "$T1 <$T2>"; $headers2 = "MIME-Version: 1.0\r\n"; $headers2 .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers2 .= "From: $MailFrom2 \r\n"; if ($MailTo2) { if (mail($MailTo2, $Subject2, $Body2, $headers2)) {} } /* Redirect browser */ $Url = "Location: http://www.uciko.com/aboutus/confirmation.php"; header($Url); /* Make sure that code below does not get executed when we redirect. */ exit(); ?>
|
|
|
|
|
|
skima (m)
|
Enhanced. Make sure u validate for a valid email address. So we will add a validation function to it. <?php /* I will advise u follow name conventiona when coding that is dim email's variable has $email and company as $company
*/
function checkEmail($email){ return preg_match("/^[^\s()<>@,;:\"\/\[\]?=]+@\w[\w-]*(\.\w[\w-]*)*\.[a-z]{2,}$/i",$email); }
//lets dim our variables
//Make sure u make it tally with the forms name
$name=$_POST['name']; // name of the person fillling the form $phone=$_POST['phone']; // his phone number $fax=$_POST['fax']; //his fax $email=$_POST['email']; //his email $company=$_POST['company']; $company_phone=$_POST['company_phone']; $company_fax=$_POST['company_fax']; $company_email=$_POST['company_email']; $project=$_POST['project']; $project_descr=$_POST['project_descr']; $currency=$_POST['currency']; $amount=$_POST[amount'];
$MailTo = "farriel@gmail.com"; $Body = "My name is $name <br> My phone number is $phone <br> My Fax number is $fax <br> My email address is $email <br> My company Name is $company <br> My company phone number is $company_phone <br> My company fax number is $company_fax <br> My company email address is $company_email <br> This project is classified as $project <br> <P> <b>Project Description:</b> $project_descr <br> We intend spending about $currency$amount on this project."; $Subject = "ATTN: New Comment from the web"; $MailFrom = "$T1 <$T2>";
$err=""; // Let validate the entry
if(empty($name)){ $err.="Please enter your name <br/>"; }
if(!ctype_digit($phone)){
$err.="Please enter a valid phone number <br/>";
} //check if this is a number if(!ctype_digit($fax)){
$err.="Please enter a valid fax number <br/>";
}
//validate email if(!checkEmail($email)){
$err.="Please enter a valid email address <br/>"; }
if(!ctype_digit($company_phone)){
$err.="Please enter a valid company's phone number <br/>";
}
if(!ctype_digit($company_fax)){
$err.="Please enter a valid company's fax number <br/>";
}
if(empty($company)){ $err.="Please enter your company's name <br/>"; }
//validate email if(!checkEmail($company_email)){
$err.="Please enter a valid email address <br/>"; }
if(empty($project)){ $err.="Please enter your project name <br/>"; } if(empty($project_descr)){ $err.="Please enter your project description<br/>"; }
if(!ctype_digit($amount)){
$err.="Please enter a valid amount You intend spending<br/>";
} //Let check if an error occured if(strlen($err)>0){ echo "<p>$err</p>"; }else{
$headers = "MIME-Version: 1.0rn"; $headers .= "Content-type: text/html; charset=iso-8859-1rn"; $headers .= "From: $MailFrom rn";
$mail1= mail($MailTo, $Subject, $Body, $headers);
$MailTo2 = "farriel@gmail.com"; $Body2 = "$Body"; $Subject2 = "$Subject"; $MailFrom2 = "$T1 <$T2>";
$headers2 = "MIME-Version: 1.0rn"; $headers2 .= "Content-type: text/html; charset=iso-8859-1rn"; $headers2 .= "From: $MailFrom2 rn";
$mail2= mail($MailTo2, $Subject2, $Body2, $headers2);
//redirect the page only if the mail was successful.
if($mail1 && $mail2){ /* Redirect browser */
$Url = "Location: http://www.uciko.com/aboutus/confirmation.php";
header($Url);
/* Make sure that code below does not get executed when we redirect. */
exit(); }else{ echo "Mail could not be sent. error occured"; } } ?>
|
|
|
|
|
|
kazey (m)
|
Complications, you dont even know whether his form is get or post, or even if he named his form properly.
|
|
|
|
|
|
skima (m)
|
@kazey
am still coding please.
I have viewed is source page.
|
|
|
|
|
|
kazey (m)
|
@kazey
am still coding please.

|
|
|
|
|
|
skima (m)
|
@farriel Change your form to this <form method="post" action=", /contact_form1.php"> <table class="border"> <tr> <td colspan="2" valign="middle" class="paraf"> </td> </tr> <tr> <td colspan="2"><span class="label"><strong>Your Contact Details </strong></span></td> </tr> <tr> <td width="103" class="paraf"><strong>Full Name</strong> <span class="style7">(Surname First)</span> <strong><span class="style16">*</span></strong></td> <td width="300"><label for="select"> <input name="name" type="text" class="paraf" id="name" size="20" /> </label></td> </tr> <tr bgcolor="#F0F0F0"> <td class="paraf"><strong>Phone</strong></td> <td> <input name="phone" type="text" class="paraf" id="phone" size="20" /></td> </tr> <tr> <td class="paraf"><strong>Fax</strong></td> <td> <input name="fax" type="text" class="paraf" id="fax" size="20" /></td> </tr> <tr bgcolor="#F0F0F0"> <td class="paraf"><strong>Email<span class="style16">*</span></strong></td> <td> <input name="email" type="text" class="paraf" id="email" size="20" /></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td colspan="2"><span class="label"><strong>Your Company Details</strong></span> </td> </tr> <tr> <td class="paraf"><strong>Name<span class="style16">*</span></strong></td> <td><label for="textfield"></label> <input name="company_name" type="text" class="paraf" id="company_name" size="20" /></td> </tr> <tr> <td bgcolor="#F0F0F0" class="paraf"><strong>Phone<span class="style16">*</span></strong></td> <td bgcolor="#F0F0F0"><label for="label2"></label> <input name="company_phone" type="text" class="paraf" id="company_phone" size="20" /></td> </tr> <tr> <td class="paraf"><strong>Fax</strong></td> <td> <input name="company_fax" type="text" class="paraf" id="company_fax" size="20" /></td> </tr> <tr> <td bgcolor="#F0F0F0" class="paraf"><strong>Email<span class="style16">*</span></strong></td> <td bgcolor="#F0F0F0"> <input name="company_email" type="text" class="paraf" id="company_email" size="20" /></td> </tr> <tr> <td> </td> <td><label for="label"></label></td> </tr> <tr bgcolor="#999999"> <td colspan="2" bgcolor="#FFFFFF"><span class="label"><strong>Your Project Information</strong> </span></td> </tr> <tr> <td bgcolor="#FFFFFF" class="paraf"><strong>Brief Project Description</strong><span class="style16">*</span> </td> <td bgcolor="#FFFFFF"> <textarea name="project_descr" cols="30" rows="4" class="paraf" id="project_descr"></textarea></td> </tr> <tr bgcolor="#F0F0F0"> <td class="paraf"><strong>Product or Service Category <span class="style16">*</span> </strong></td> <td><select name="project" class="paraf" id="project"> <option>Please Select, </option> <option value="Gypsum">Gypsum</option> <option value="Grid">Grid</option> <option value="Suspended Ceilings">Suspended Ceilings</option> <option value="Industrial Chemicals">Industrial Chemicals</option> <option value="Sales">Sales </option> <option value="Distributorship">Distributorship</option> <option value="Clearing, Forwarding">Clearing, Forwarding</option> <option value="Warehousing">Warehousing</option> <option value="Haulage">Haulage</option> </select> </td> </tr> <tr> <td bgcolor="#FFFFFF" class="paraf"><strong>Project Budget<span class="style16">*</span></strong></td> <td bgcolor="#FFFFFF"><table width="300"> <tr> <td width="100"> <select name="currency" class="paraf" id="D2"> <option value="$">US Dollars</option> <option value="Pounds">UK Pounds</option> <option value="=N=">Naira</option> </select> </td> <td width="188"> <input name="amount" type="text" id="amount" size="20" /></td> </tr> </table></td> </tr> <tr bgcolor="#F0F0F0"> <td> </td> <td><input name="B1" type="submit" class="paraf" id="B1" value="Contact Me" /></td> </tr>
|
|
|
|
|
|
kazey (m)
|
Nice work, people can be very nice on Nairaland. 
|
|
|
|
|
|
skima (m)
|
We are here to help one another.
|
|
|
|
|
|
Farriel (m)
|
Christ! You're my man, Skima!  All that code, for free? You're my man! And Kazey, thanks to you to.
|
|
|
|
|
|
skima (m)
|
have u tested it?
I have not though.
|
|
|
|
|
|
Farriel (m)
|
Yeah, even though I had to tweak some lines of code. The company field wasn't recognizing entries and still prompting users for company name, even though they had done that. I had to delete the print error variables.
So right now, no company name is coming through. But all the same man, I really appreciate this.
I wish I could your number or something so I could call you when I need to. Perhaps then I just might want to pay you for your time. Thanks Skima.
|
|
|
|
|
|
skima (m)
|
change this : $company=$_POST['company'];
to : $company=$_POST['company_name'];
Dont make any change to your form.
my number 08027924441
|
|
|
|
|
|
Farriel (m)
|
Finding this a little lately, all the same thanks.
Would call you soon, pal,
|
|
|
|
|
|