• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • Last Modified:

Fix Email Form output

Hello I hope someone is able to help with this problem I don't know php very well.

I have the following email form:

<?php

$my_email = "emailaddres@emailaddress.com";

if ($_SERVER['REQUEST_METHOD'] != "POST"){exit;}

$message = "";

while(list($key,$value) = each($_POST)){if(!(empty($value))){$set=1;}$message = $message . "$key: $value\n\n";} if($set!==1){header("location: $_SERVER[HTTP_REFERER]");exit;}

$subject = "New Sign Up";
$headers = "From: " . $_POST['Email'] . "\n" . "Return-Path: " . $_POST['Email'] . "\n" . "Reply-To: " . $_POST['Email'] . "\n";

mail($my_email,$subject,$message,$headers);

?>

This works fine. What I need it the following changes to the php code to put the phone number on one line as phone number and not the filed names.
.
Here is the form that is sending the data.

<script language="JavaScript">
function checkrequired(which) {
var pass=true;
if (document.images) {
for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];
if (tempobj.name.substring(0,8)=="required") {
if (((tempobj.type=="text"||tempobj.type=="textarea")&&
tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
tempobj.selectedIndex==0)) {
pass=false;
break;
         }
      }
   }
}
if (!pass) {
shortFieldName=tempobj.name.substring(8,30).toUpperCase();
alert("Please make sure the "+shortFieldName+" field was properly completed.");
return false;
}
else
return true;
}

</script>

<form action="pstingform.php" method="POST" ">
  <table cellSpacing="0" cellPadding="0" width="90%" align="center" bgColor="#000000" border="0">
    <tr>
      <td style="font-size: 10pt; font-family: MS Sans Serif">
      <div class="ABCONFLIST">
          <table cellSpacing="1" cellPadding="2" width="100%" align="center" border="0">
            <tr bgColor="#cccccc">
              <td class="PFTDL" vAlign="top" bgcolor="#8F7AA0"><font color="#FFFFFF" size="3" face="Arial Narrow"><strong>*Select
                City Board</strong></font></td>
              <td class="PFTDR" bgcolor="#8F7AA0"><select name="City">
                  <option value="Colorado" selected>Colorado</option>
                  <option value="Dallas">Dallas</option>
                  <option value="Houston">Houston</option>
                  <option value="Seattle">Seattle</option>
                  <option value="Other">Other</option>
                </select></td>
            </tr>
            <tr bgColor="#cccccc">
              <td class="PFTDL" vAlign="top" width="35%" bgcolor="#8F7AA0"><b>
                <font color="#FFFFFF" face="Arial Narrow" size="3">* Name</font></b></td>
              <td class="PFTDR" bgcolor="#8F7AA0"> <input type="text" size="40" name="Name" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt" id="requiredName"></td>
            </tr>
            <tr>
              <td class="PFTDL" vAlign="top" bgcolor="#8F7AA0"><b><font color="#FFFFFF" face="Arial Narrow" size="3">*
                Phone number - IMPORTANT!</font></b></td>
              <td class="PFTDR" bgcolor="#8F7AA0">(
                <input name="requiredArea-Code" type="text" size="3" maxlength="3" value="" tabindex="1" onkeyup="return autoTab(this,3,event);">
                )
                <input name="requiredPrefix-Of-Phone-Number" type="text" size="3" maxlength="3" value="" tabindex="2" onkeyup="return autoTab(this,3,event);">
                -
                <input name="requiredLast-4-Digits-Of-Phone" type="text" size="4" maxlength="4" value="" tabindex="3"></td>
            </tr>
            <tr>
              <td class="PFTDL" vAlign="top" width="35%" bgcolor="#8F7AA0"><b>
                <font color="#FFFFFF" face="Arial Narrow" size="3">* Email address</font></b></td>
              <td class="PFTDR" bgcolor="#8F7AA0"> <input type="text"  size="40" name="EmailAddress" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt"id="requiredEmail"></td>
            </tr>
            <tr>
              <td class="PFTDL" vAlign="top" width="35%" bgcolor="#8F7AA0"><b>
                <font color="#FFFFFF" face="Arial Narrow" size="3">* Independent
                or agency?</font></b></td>
              <td class="PFTDR" bgcolor="#8F7AA0"> <input type="text"  size="40" name="IndependentOrAgency" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt" id="requiredIndependentAgency"></td>
            </tr>
            <tr bgColor="#cccccc">
              <td class="PFTDL" vAlign="top" width="35%" bgcolor="#8F7AA0"><b>
                <font color="#FFFFFF" face="Arial Narrow" size="3">* Posting Name(s)</font></b></td>
              <td class="PFTDR" bgcolor="#8F7AA0"> <input type="text" size="40" name="PostingName" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt" id="requiredPostingName"></td>
            </tr>
            <tr bgColor="#cccccc">
              <td class="PFTDL" vAlign="top" width="35%" bgcolor="#8F7AA0"><b>
                <font color="#FFFFFF" face="Arial Narrow" size="3">* Password</font></b></td>
              <td class="PFTDR" bgcolor="#8F7AA0"> <input type="text" size="40" name="Password" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt" id="requiredPassword"></td>
            </tr>
            <tr>
              <td class="PFTDL" vAlign="top" width="35%" bgcolor="#8F7AA0"><b>
                <font color="#FFFFFF" face="Arial Narrow" size="3">* Retype Password</font></b></td>
              <td class="PFTDR" bgcolor="#8F7AA0"> <input type="text" size="40" name="RetypePassword" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt" id="requiredRetypePassword"></td>
            </tr>
            <tr bgColor="#cccccc">
              <td class="PFTDL" vAlign="top" width="35%" bgcolor="#8F7AA0">&nbsp;</td>
              <td class="PFTDR" bgcolor="#8F7AA0">&nbsp;</td>
            </tr>
            <tr bgColor="#cccccc">
              <td class="PFTDL" vAlign="top" width="35%" bgcolor="#8F7AA0"> <font color="#FFFFFF" face="Arial Narrow" size="3"><b>Notes:</b></font></td>
              <td class="PFTDR" bgcolor="#8F7AA0"> <textarea rows="15" name="Notes" cols="48"></textarea></td>
            </tr>
            <tr bgColor="#efefee">
              <td style="font-size: 10pt; font-family: MS Sans Serif" bgcolor="#8F7AA0" align="center">
                <input class="buttonstyle" type="reset" value="Reset"> </td>
              <td style="font-size: 10pt; font-family: MS Sans Serif" bgcolor="#8F7AA0" align="center">
                <br> <input class="buttonstyle" type="submit" value="Submit!">
                <br> &nbsp;</td>
            </tr>
          </table>
      </div>
      </td>
    </tr>
  </table>
</form>

here is the current output and what i could like to get.

Current PHP

City: Colorado

Name: form test

requiredArea-Code: 999

requiredPrefix-Of-Phone-Number: 999

requiredLast-4-Digits-Of-Phone: 9999

EmailAddress: email@emailaddress.com

IndependentOrAgency: independent

PostingName: niteone

Password: 123199

RetypePassword: 123199

Notes: kl


Needed look

City: Colorado

Name: form test

Phone: 999-999-9999

EmailAddress: email@emaiaddress.com

IndependentOrAgency: independent

PostingName: niteone

Password: 123199

RetypePassword: 123199

Notes: kl


Thank you in advance.
0
ComputerTechie
Asked:
ComputerTechie
  • 3
1 Solution
 
mmc98dl1Commented:
here is how I do it, you will need to insert your header and footer to the confirmation screen at the bottom - but this looks loads professional.

<?

//put vals in form
$form = '
 <table cellSpacing="0" cellPadding="0" width="90%" align="center" bgColor="#000000" border="0">
    <tr>
      <td style="font-size: 10pt; font-family: MS Sans Serif">
      <div class="ABCONFLIST">
          <table cellSpacing="1" cellPadding="2" width="100%" align="center" border="0">
            <tr bgColor="#cccccc">
              <td class="PFTDL" vAlign="top" bgcolor="#8F7AA0"><font color="#FFFFFF" size="3" face="Arial Narrow"><strong>*Select
                City Board</strong></font></td>
              <td class="PFTDR" bgcolor="#8F7AA0">'.$_POST["City"].'</td>
            </tr>
            <tr bgColor="#cccccc">
              <td class="PFTDL" vAlign="top" width="35%" bgcolor="#8F7AA0"><b>
                <font color="#FFFFFF" face="Arial Narrow" size="3">* Name</font></b></td>
              <td class="PFTDR" bgcolor="#8F7AA0">'.$_POST["Name"].'</td>
            </tr>
            <tr>
              <td class="PFTDL" vAlign="top" bgcolor="#8F7AA0"><b><font color="#FFFFFF" face="Arial Narrow" size="3">*
                Phone number - IMPORTANT!</font></b></td>
              <td class="PFTDR" bgcolor="#8F7AA0">('.$_POST["requiredArea-Code"].')
                '.$_POST["requiredPrefix-Of-Phone-Number"].'-'.$_POST["requiredLast-4-Digits-Of-Phone"].'</td>
            </tr>
            <tr>
              <td class="PFTDL" vAlign="top" width="35%" bgcolor="#8F7AA0"><b>
                <font color="#FFFFFF" face="Arial Narrow" size="3">* Email address</font></b></td>
              <td class="PFTDR" bgcolor="#8F7AA0">'.$_POST["EmailAddress"].'</td>
            </tr>
            <tr>
              <td class="PFTDL" vAlign="top" width="35%" bgcolor="#8F7AA0"><b>
                <font color="#FFFFFF" face="Arial Narrow" size="3">* Independent
                or agency?</font></b></td>
              <td class="PFTDR" bgcolor="#8F7AA0"> '.$_POST["IndependentOrAgency"].'</td>
            </tr>
            <tr bgColor="#cccccc">
              <td class="PFTDL" vAlign="top" width="35%" bgcolor="#8F7AA0"><b>
                <font color="#FFFFFF" face="Arial Narrow" size="3">* Posting Name(s)</font></b></td>
              <td class="PFTDR" bgcolor="#8F7AA0">'.$_POST["PostingName"].'</td>
            </tr>
            <tr bgColor="#cccccc">
              <td class="PFTDL" vAlign="top" width="35%" bgcolor="#8F7AA0"><b>
                <font color="#FFFFFF" face="Arial Narrow" size="3">* Password</font></b></td>
              <td class="PFTDR" bgcolor="#8F7AA0"> '.$_POST["Password"].'</td>
            </tr>
            <tr>
              <td class="PFTDL" vAlign="top" width="35%" bgcolor="#8F7AA0"><b>
                <font color="#FFFFFF" face="Arial Narrow" size="3">* Retype Password</font></b></td>
              <td class="PFTDR" bgcolor="#8F7AA0"> '.$_POST["ReTypePassword"].'</td>
            </tr>
            <tr bgColor="#cccccc">
              <td class="PFTDL" vAlign="top" width="35%" bgcolor="#8F7AA0">&nbsp;</td>
              <td class="PFTDR" bgcolor="#8F7AA0">&nbsp;</td>
            </tr>
            <tr bgColor="#cccccc">
              <td class="PFTDL" vAlign="top" width="35%" bgcolor="#8F7AA0"> <font color="#FFFFFF" face="Arial Narrow" size="3"><b>Notes:</b></font></td>
              <td class="PFTDR" bgcolor="#8F7AA0">'.$_POST["Notes"].'</td>
            </tr>
          </table>
      </div>
      </td>
    </tr>
  </table>
';

//Put together email
$mailContent = '

<html>
<body>
<table align="center" width="80%">
      <tr>
            <td>
        '.$form.'
            </td>
      </tr>
</table>
</body>
</html>
';

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$_POST["EmailAddress"]."\r\n";

$submitDate = date("F j, Y, g:i a");
$pageTitle = "User Form";
$subject = $pageTitle." from yourdomain.com - ".$submitDate;
mail("you@yourdomain.com",$subject,$mailContent,$headers);

//include("header.php");
print("Your user form has been sent, please print this page for your records.");
print("This form was submitted on ".$submitDate);
print($form);
//include("footer.php");
?>
0
 
ComputerTechieAuthor Commented:
i will test the new changes today. thank you
0
 
ComputerTechieAuthor Commented:
this worked great.

thank you i accept this answer.

0
 
ComputerTechieAuthor Commented:
give 225 to mmc98dl1
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now