?
Solved

PHP Form on Fatshosts Server

Posted on 2009-07-15
6
Medium Priority
?
222 Views
Last Modified: 2012-05-07
I have been trying for a good several hours now to get a working form on my customers site.
http://www.palletnetworkanglia.co.uk/contactus.html

Fields I require are.
Name:
Telephone:
Email Address:
Collection Post Code:
Where did you hear about us:
Message:

I have contacted Fasthosts who have given me the script below which I have very messily (Messed up). I need the form data to goto jason@userone.co.uk and the data to come from Jason@letum.co.uk.

I hope this makes sense to some one as I cant seem to get my head round php! I would like to loose the email from field.

Thanks

Jason
<?php
$email_to = "jason@userone.co.uk";
if (! empty($_POST['email']) )
{
 
  $message=$_POST["message"];
  $email=$_POST["email"];
  $fromadd=$_POST["fromadd"];
  $name=$_POST["name"];
  $telephone=$_POST["telephone"];
  $collection=$_POST["collection"];
  $where=$_POST["where"];
 
  $content = "You have a New Query From {$name}
  Tel No: {$telephone}
  Email: {$email}
  Collection Post Code: {$collection}
  
  Message: {$message}
  
  Where did you hear about us? {$where}";
 
  ini_set("sendmail_from" , "jason@letum.co.uk");
  ini_set("SMTP", "smtp.fasthosts.co.uk");
  $mailSent = false;
  $mailSent = mail( $email, "Pallet Network Anglia Contact Form", $content, "From: $fromadd", "-fjason@letum.co.uk".$fromadd );
 
  if ($mailSent)
  {
    echo 'Mail sent';
  }
  else
  {
    echo 'Problem';
  }
}
else
{
 
?>
<html>
<head>
<title>Contact Form</title>
<style type="text/css">
<!--
.style1 {
	font-size: 12px;
	font-weight: bold;
}
-->
</style>
</head>
<body bgcolor="white">
</body>
</head>
</html>
<?
}
?>

Open in new window

0
Comment
Question by:jasonuocs
[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
  • 3
6 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 24865568
Try this example.  You can fill in the rest of the fields, as needed.  Hope that helps, ~Ray
<?php // RAY_form_to_mail.php
error_reporting(E_ALL);
 
// SEND MAIL FROM A FORM
 
// AVOID BECOMING AN OPEN-RELAY FOR SPAM
function clean_string($str)
{
    $str = stripslashes($str);
    $str = trim(ereg_replace(" +", " ", $str));
    $str = ereg_replace('[^ a-zA-Z0-9&+:?_\.\-]', '', $str);
return $str;
}
 
// REQUIRED VALUES ARE PREPOPULATED
$to    = "jason@userone.co.uk";
$to    = "RPaseur@NatPresCh.org";
$from  = "fjason@letum.co.uk";
$subj  = "Pallet Network Anglia Contact Form";
 
// IF THE DATA HAS BEEN POSTED
if (!empty($_POST['email']))
{
 
// CLEAN UP THE POTENTIALLY BAD AND DANGEROUS DATA
    $email      = clean_string($_POST["email"]);
    $name       = clean_string($_POST["name"]);
    $telephone  = clean_string($_POST["telephone"]);
 
// CONSTRUCT THE MESSAGE
    $content    = "You have a New Query From $name \n\n";
    $content   .= "Tel No: $telephone\n";
    $content   .= "Email: $email\n";
 
// SEND MAIL
    if (!mail( $to, $subj, $content, "From: $from\r\n"))
    {
       die("MAIL FAILED FOR $to");
    } else
    {
       die("MAIL SUCCEEDED FOR $to");
    }
} // END OF PHP - PUT UP THE FORM
?>
<form method="post">
<br/>Email: <input name="email" />
<br/>Phone: <input name="telephone" />
<br/>Name:  <input name="name" />
<br/><input type="submit" />
</form>

Open in new window

0
 
LVL 2

Author Comment

by:jasonuocs
ID: 24873971
Hi Ray,

Thanks for the reply. I copied & pasted this to a test php area but I did not receive an email. Sure I am doing something wrong just not to up on this.

I have found the following which works but I can not see how to add the other required fields.
Message section is working, it's the other fields...

<?php
$to = "jason@userone.co.uk";
$subject = "Test mail";
$message = $_POST["message"];
$from = "jason@letum.co.uk";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

Fields required.

Name:
Telephone:
Email Address:
Collection Post Code:
Where did you hear about us:
Message:

Thanks

Jason
User One
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 24874235
No, I received the email.  Try taking out line 17 from the code snippet I posted above.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:jasonuocs
ID: 24874418
Hi Ray,

That 's working great now thanks. How do I add the extra fields I require?
Name: IS GOOD
Telephone: IS GOOD
Email Address: IS GOOD
Collection Post Code: NOT INCLUDED IN EMAIL
Where did you hear about us: NOT INCLUDED IN EMAIL
Message: NOT INCLUDED IN EMAIL

Thanks for your help with this. It is very much appreciated.

Jason
0
 
LVL 2

Author Closing Comment

by:jasonuocs
ID: 31604028
Spot on. Thanks for your help Ray. cracked the last little bit as you had made it very clear when I actually read it properly. Thanks Again
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 24879732
You need to add the input fields to the HTML form (line 46, et seq) and you need to add the processing for these fields to the action script (lines 25, et seq).  There is a one-to-one relationship between the name= field in the HTML form and the $_POST key, like this:

<input name="xyz" type="text" />

puts its data into

$_POST["xyz"]

best regards, ~Ray
0

Featured Post

Tutorial: Introduction to Managing a Linux Server

In this tutorial on systemd, we will explore:
-OS/Distro Adoption
-chkconfig and Other Legacy Commands
-Summary and Key Commands

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

765 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