Solved

Php email not sending field values

Posted on 2008-06-11
5
179 Views
Last Modified: 2010-08-05
Please see the attached php email script. When I submit this form (www.mwebdev.com/stat/employment.html), I get the email successfully. However, I only get the labels, and not the field values. The php script only has a few of the first fields to this point. I will add them after I get the email working successfully. Thanks for your help in advance.
<?php
 
 
// get posted data into local variables
$EmailFrom = "website@domainhere.com";
$EmailTo = "realemailhere.com";
$Subject = "Email from Website";
$Name = Trim(stripslashes($_POST['name'])); 
$Phone = Trim(stripslashes($_POST['phone1'])); 
$Email = Trim(stripslashes($_POST['email'])); 
 
 
// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}
 
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Home Phone: ";
$Body .= $phone1;
$Body .= "\n";
$Body .= "Office Phone: ";
$Body .= $phone2;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $address;
$Body .= "\n";
$Body .= "City: ";
$Body .= $city;
$Body .= "\n";
$Body .= "State: ";
$Body .= $state;
$Body .= "\n";
$Body .= "Zip: ";
$Body .= $zip;
$Body .= "\n";
 
// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
 
// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=appsent.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

Open in new window

0
Comment
Question by:isaacr25
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:isaacr25
ID: 21764699
One addition: the php script is not uploaded to the location I posted; only the form is uploaded. Thanks.
0
 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21764729
PHP is case sensitive for variables.  See the attached.
<?php
 
 
// get posted data into local variables
$EmailFrom = "website@domainhere.com";
$EmailTo = "realemailhere.com";
$Subject = "Email from Website";
$name = Trim(stripslashes($_POST['name'])); 
$phone1 = Trim(stripslashes($_POST['phone1'])); 
$email = Trim(stripslashes($_POST['email'])); 
 
 
// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}
 
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Home Phone: ";
$Body .= $phone1;
$Body .= "\n";
$Body .= "Office Phone: ";
$Body .= $phone2;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $address;
$Body .= "\n";
$Body .= "City: ";
$Body .= $city;
$Body .= "\n";
$Body .= "State: ";
$Body .= $state;
$Body .= "\n";
$Body .= "Zip: ";
$Body .= $zip;
$Body .= "\n";
 
// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
 
// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=appsent.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

Open in new window

0
 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21764735
You'll now have name, phone1, and email working.  Others you will need to add.  Just remember to check the capitalisation!
0
 

Author Comment

by:isaacr25
ID: 21765197
Only my labels are capitalized. As far as I can tell, my variables are lower-case. Where do you see different in the code... I can't see the difference between my code and yours. Thanks.
0
 
LVL 24

Accepted Solution

by:
purplepomegranite earned 500 total points
ID: 21765225
Your code:
$Name = Trim(stripslashes($_POST['name']));
$Phone = Trim(stripslashes($_POST['phone1']));
$Email = Trim(stripslashes($_POST['email']));

My code:
$name = Trim(stripslashes($_POST['name']));
$phone1 = Trim(stripslashes($_POST['phone1']));
$email = Trim(stripslashes($_POST['email']));
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to dynamically set the form action using jQuery.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question