Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,147,761 members, 7,798,546 topics. Date: Tuesday, 16 April 2024 at 05:31 AM

Php Form To Mail Problem - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Php Form To Mail Problem (2312 Views)

Connecting Vb.net 2010 window Form To Sql Server Online / How Do I Connect A Form To Mysql Database / Php Form To Mail (2) (3) (4)

(1) (Reply) (Go Down)

Php Form To Mail Problem by Farriel(m): 12:06pm On Jun 23, 2006
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.
Re: Php Form To Mail Problem by kazey(m): 12:47pm On Jun 23, 2006
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>';
Re: Php Form To Mail Problem by sbucareer(f): 1:41pm On Jun 23, 2006

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
Re: Php Form To Mail Problem by kazey(m): 1:46pm On Jun 23, 2006
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.
Re: Php Form To Mail Problem by skima(m): 11:05pm On Jun 23, 2006
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();
?>
Re: Php Form To Mail Problem by skima(m): 11:32pm On Jun 23, 2006
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.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: $MailFrom \r\n";


$mail1= 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";



$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";
}
}
?>

Re: Php Form To Mail Problem by kazey(m): 11:37pm On Jun 23, 2006
Complications, you dont even know whether his form is get or post, or even if he named his form properly.
Re: Php Form To Mail Problem by skima(m): 11:49pm On Jun 23, 2006
@kazey

am still coding please.

I have viewed is source page.
Re: Php Form To Mail Problem by kazey(m): 11:54pm On Jun 23, 2006
skima:

@kazey

am still coding please.

smiley
Re: Php Form To Mail Problem by skima(m): 12:02am On Jun 24, 2006
@farriel

Change ur form to this

<form method="post" action=", /contact_form1.php">
<table class="border">
<tr>
<td colspan="2" valign="middle" class="paraf">&nbsp;</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>&nbsp;</td>
<td>&nbsp;</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>&nbsp;</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>&nbsp;</td>
<td><input name="B1" type="submit" class="paraf" id="B1" value="Contact Me" /></td>
</tr>
Re: Php Form To Mail Problem by kazey(m): 12:05am On Jun 24, 2006
Nice work, people can be very nice on Nairaland. smiley
Re: Php Form To Mail Problem by skima(m): 12:27am On Jun 24, 2006
We are here to help one another.
Re: Php Form To Mail Problem by Farriel(m): 7:24pm On Jun 24, 2006
Christ! You're my man, Skima! shocked All that code, for free? You're my man!

And Kazey, thanks to you to.
Re: Php Form To Mail Problem by skima(m): 6:45pm On Jun 25, 2006
have u tested it?

I have not though.

Re: Php Form To Mail Problem by Farriel(m): 3:26pm On Jun 27, 2006
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.
Re: Php Form To Mail Problem by skima(m): 3:00pm On Jun 28, 2006
change this : $company=$_POST['company'];

to : $company=$_POST['company_name'];

Dont make any change to your form.

my number 08027924441

Re: Php Form To Mail Problem by Farriel(m): 6:37pm On Jul 08, 2006
Finding this a little lately, all the same thanks.

Would call you soon, pal,

(1) (Reply)

Free Camscan Download / What Digital Skill Can One Learn On Phone / What Type Of Solar Inverter Would You Recommend For Someone Learning Programming

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 57
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.