Jump to content

php fields array help


srcfresno

Recommended Posts

Below is my php file from my website srcfresno.com/inquiry2.htm

 

When I go to the website and enter information in the form fields, it submits to my email fine but the email I receive has no information filled in. Please help. Not sure why

 

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>Statistics & Research Consulting</title>

</head>

<?php

$to = '[email protected]';

$subject = 'Contact Inquiry form';

$firstname = $_REQUEST['First Name'] ;

$lastname = $_REQUEST['Last Name'] ;

$from = $_REQUEST['Email'] ;

$phone = $_REQUEST['Phone'] ;

$company = $_REQUEST['Company Website (if applicable)'] ;

$messege = $_REQUEST['Please describe your interest in Statistics & Research Consulting'] ;

 

$fields = array(

'firstname' => 'First Name',

'lastname' => 'Last Name',

'from' => 'Email',

'phone' => 'Phone',

'company' => 'Company Website (if applicable)',

'message' => 'Please describe your interest in Statistics & Research Consulting'

);

 

$body = "We have received the following information from $_SESSION[username]:\n\n";

foreach($_REQUEST as $a => $b){

if(array_key_exists($a, $fields) && !empty($b)){

  $part1 .= sprintf("%20s: %s\n", $fields[$a], $b);

}

 

$send = mail($to, $subject, $body);

 

if($send)

{print "Thank you for contacting us. We have received your information and a SRC Consultant will respond shortly."; }

else

{print "We encountered an error sending your mail, please notify [email protected]"; }

 

?>

 

<body>

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/245542-php-fields-array-help/
Share on other sites

This is the correct php code

 

<?php 
$to = '[email protected]';
$subject = 'Contact Inquiry form'; 
$firstname = $_REQUEST['First Name'] ;
$lastname = $_REQUEST['Last Name'] ;
$from = $_REQUEST['Email'] ;
$phone = $_REQUEST['Phone'] ; 
$company = $_REQUEST['Company Website (if applicable)'] ;
$messege = $_REQUEST['Please describe your interest in Statistics & Research Consulting'] ;
  
$fields = array( 
'firstname' => 'First Name',
'lastname' => 'Last Name',
'from' => 'Email',
'phone' => 'Phone',
'company' => 'Company Website (if applicable)',
'message' => 'Please describe your interest in Statistics & Research Consulting'
); 

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ 	$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
  
$send = mail($to, $subject, $body); 

if($send)
{print "Thank you for contacting us. We have received your information and a SRC Consultant will respond shortly."; } 
else 
{print "We encountered an error sending your mail, please notify [email protected]"; }

?> 


<body><form action="contact.php" method="post" enctype="multipart/form-data" name="input" target=_blank>
    <h2><span class="style14">Contact Inquiry Form </span></h2>
    <p> </p>
    <p>
      <span class="style24 style2">Customer Name</span>
      <br>
      <input name="textfield" type="text" size="50">
    First Name<br>
    <br>
    <input name="textfield" type="text" size="50">
  Last Name</br>
    </p>
    <p>
      <span class="style24 style2">Email</span><br>
  <input name="textfield" type="text" size="50">
  </br> </p>
    <p>      <span class="style24 style2">Phone</span>
  <br>
  <input name="textfield" type="text" size="50">
  </br> </p>
<p>
  <span class="style24 style2">Company Website (if applicable)</span>
  <br>
  <input name="textfield" type="text" size="50">
  </br> </p>
<p>
  <span class="style24 style2">Please describe your interest in Statistics & Research Consulting</span>  
      <br>
      <textarea name="textarea" cols="50" rows="10"></textarea>
  </br></p> 
    <p>
      <input type="submit" name="Submit" value="Submit">
  </p>
  </form>

Try

 

Form

<body><form action="contact.php" method="post"  name="input" target=_blank>
    <h2><span class="style14">Contact Inquiry Form </span></h2>
    <p> </p>
    <p>
      <span class="style24 style2">Customer Name</span>
      <br>
      <input name="firstname" type="text" size="50">
    First Name<br>
    <br>
    <input name="lastname" type="text" size="50">
  Last Name</br>
    </p>
    <p>
      <span class="style24 style2">Email</span><br>
  <input name="email" type="text" size="50">
  </br> </p>
    <p>      <span class="style24 style2">Phone</span>
  <br>
  <input name="phone" type="text" size="50">
  </br> </p>
<p>
  <span class="style24 style2">Company Website (if applicable)</span>
  <br>
  <input name="company" type="text" size="50">
  </br> </p>
<p>
  <span class="style24 style2">Please describe your interest in Statistics & Research Consulting</span>  
      <br>
      <textarea name="message" cols="50" rows="10"></textarea>
  </br></p> 
    <p>
      <input type="submit" name="Submit" value="Submit">
  </p>
  </form>

 

contact

<?php 
$to = '[email protected]';
$subject = 'Contact Inquiry form'; 
if (get_magic_quotes_gpc()) { $_POST = array_map('stripslashes',$_POST); }
  
$fields = array( 
'firstname' => 'First Name',
'lastname' => 'Last Name',
'email' => 'Email',
'phone' => 'Phone',
'company' => 'Company Website (if applicable)',
'message' => 'Please describe your interest in Statistics & Research Consulting'
); 

$body = "We have received the following information:\n\n"; 
foreach($fields as $a => $b) { 	
if(array_key_exists($a,$_POST)) {
	$body .= sprintf("%s: %s\n",$b,$_POST[$a]);
}
}
  
$send = mail($to, $subject, $body); 

if($send)
{print "Thank you for contacting us. We have received your information and a SRC Consultant will respond shortly."; } 
else 
{print "We encountered an error sending your mail, please notify [email protected]"; }

?> 

 

Let us know how it goes.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.