Php Form To Mail Problem

Welcome. Please Login, Register, Or Activate! 
type your username and password to login
Date: November 25, 2009, 01:11 AM
432147 members and 299113 Topics
Latest Member: Jimoh Iyanda
Nairaland [Nigerian Forum] Home Help Search Who is currently online? Login Register
Nairaland Forum  |  Technology  |  Programming  |  Php Form To Mail Problem
Pages: (1) Go Down Send this topic Notify of replies
Author Topic: Php Form To Mail Problem  (Read 531 views)
Farriel (m)
Php Form To Mail Problem
« on: June 23, 2006, 12:06 PM »

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)
Re: Php Form To Mail Problem
« #1 on: June 23, 2006, 12:47 PM »

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)
Re: Php Form To Mail Problem
« #2 on: June 23, 2006, 01:41 PM »


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)
Re: Php Form To Mail Problem
« #3 on: June 23, 2006, 01:46 PM »

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)
Re: Php Form To Mail Problem
« #4 on: June 23, 2006, 11:05 PM »

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)
Re: Php Form To Mail Problem
« #5 on: June 23, 2006, 11:32 PM »

Enhanced.
Make sure u validate for a valid email address. So we will add a validation function to it.

Code:
<?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-Version1.0rn"; 
$headers .= "
Content-typetext/htmlcharset=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-Version1.0rn"; 
$headers2 .= "
Content-typetext/htmlcharset=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 = "
Locationhttp://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";
}
}
?>


* php.gif (2.46 KB, 120x67 )
kazey (m)
Re: Php Form To Mail Problem
« #6 on: June 23, 2006, 11:37 PM »

Complications, you dont even know whether his form is get or post, or even if he named his form properly.
skima (m)
Re: Php Form To Mail Problem
« #7 on: June 23, 2006, 11:49 PM »

@kazey

am still coding please.

I have viewed is source page.
kazey (m)
Re: Php Form To Mail Problem
« #8 on: June 23, 2006, 11:54 PM »

Quote from: skima on June 23, 2006, 11:49 PM
@kazey

am still coding please.

Smiley
skima (m)
Re: Php Form To Mail Problem
« #9 on: June 24, 2006, 12:02 AM »

@farriel

Change your form to this

Code:
<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>
kazey (m)
Re: Php Form To Mail Problem
« #10 on: June 24, 2006, 12:05 AM »

Nice work, people can be very nice on Nairaland.  Smiley
skima (m)
Re: Php Form To Mail Problem
« #11 on: June 24, 2006, 12:27 AM »

We are here to help one another.
Farriel (m)
Re: Php Form To Mail Problem
« #12 on: June 24, 2006, 07:24 PM »

Christ! You're my man, Skima!  Shocked All that code, for free? You're my man!

And Kazey, thanks to you to.
skima (m)
Re: Php Form To Mail Problem
« #13 on: June 25, 2006, 06:45 PM »

have u tested it?

I have not though.


* phpng2.jpg (8.99 KB, 120x55 )
Farriel (m)
Re: Php Form To Mail Problem
« #14 on: June 27, 2006, 03:26 PM »

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)
Re: Php Form To Mail Problem
« #15 on: June 28, 2006, 03:00 PM »

change this : $company=$_POST['company'];

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

Dont make any change to your form.

my number 08027924441


* phpng2.jpg (11.39 KB, 138x73 )
Farriel (m)
Re: Php Form To Mail Problem
« #16 on: July 08, 2006, 06:37 PM »

Finding this a little lately, all the same thanks.

Would call you soon, pal,
 Computer Science: Where Do I Go From Here?  Free Ccna Dumps  Hello All I Am New To Programming  Page 2
Pages: (1) Go Up Send Topic to Friend by E-mail Reply 


Sections: Autos/Cars (2) Jobs/Vacancies (2) (3) Career Talk Education General(2) Politics Romance Computers Phones Travel
Sports Fashion Health Religion Celebrities TV/Movies (2) Music/Radio (2) Books Webmasters Programming

Links: Page1 Page2 Page3 Page4 Page5 Page6 Page7 Page8 Page9 Page10

Nairaland is owned by Oluwaseun Osewa. See also: Nairalist Classified Ads
Nairaland Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.