Solved

Php email not sending field values

Posted on 2008-06-11
5
171 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
  • 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now