Welcome to Tech Support Forum home to more then 136,000 problems solved. Issues have included: Spyware, Malware, Virus Issues, Windows, Microsoft, Linux, Networking, Security, Hardware, and Gaming Getting your problem solved is as easy as:
1. Registering for a free account
2. Asking your question
3. Receiving an answer

Registered members:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* See fewer ads.
* And much more..

 





Want to know how to post a question? click here Having problems with spyware and pop-ups? First Steps
Go Back   Tech Support Forum > Design Forum > Web Design & Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read

Web Design & Programming Discussion of web design, and server-side & client-side scripting

Reply
 
Thread Tools
Old 04-23-2008, 10:15 AM   #1 (permalink)
Registered User
 
Cerilia's Avatar
 
Join Date: Apr 2008
Location: England
Posts: 11
OS: XP Pro SP2


Driving me crazy!

Hi People, I wonder if I can pick your brains...

Firstly I've never coded in PHP before so this is all new to me...

I need a simple form filled out online, that can be submitted.

I came up with this; but its not working, no mail, no nothing!

please help!

Code:
<form id="rwform" class="contactform" method="post" action="sendmail.php">

<div id="contactform">
<label for="name">Name</label>
<input  type="text" name="name" id="user" value="" />
</div>

<div id="contactform">
<label for="address">Address</label>
<input type="text" name="address" id="user" value="" />
</div>

<div id="contactform">
<label for="telephone">Telephone</label>
<input type="text" name="telephone"  id="user" value="" />
</div>

<div id="contactform">
<label for="email">Email Address:</label>
<input  type="text" name="email" id="emailaddress" value="" />
</div>

<div id="contactform">
<label for="enquiry">Enquiry:</label>
<textarea name="enquiry" id="enquiry" rows="5" cols="25"></textarea>
</div>

<div id="contactform">
<label for="hearaboutus">How did you hear about us?</label>
<input type="checkbox" name="websearch" /> Web Search<br />
<input type="checkbox" name="recommended" class="threepxfix" /> Recommended<br />
<input type="checkbox" name="mag_ad" class="threepxfix" /> Magazine Advert<br />
<input type="checkbox" name="flyer" class="threepxfix" /> Flyer<br />
</div>
<div style="margin-left: 150px;">
<input type="submit" value="Submit" /> <input type="reset" value="reset" />
</div>

</form>
PHP

Code:
<?php

$_POST = array_map('strip_tags', $_POST);  
$name = $_REQUEST['name'] ;
$address = $_REQUEST['address'] ;
$telephone = $_REQUEST['telephone'] ;
$email = $_REQUEST['email'] ;
$enquiry = $_REQUEST['enquiry'] ;
$websearch = $_REQUEST['websearch'] ;
$recommended = $_REQUEST['recommended'] ;
$mag_ad = $_REQUEST['mag_ad'] ;
$flyer = $_REQUEST['flyer'] ;

mail("myaddress@mail.co.uk", "Web Enquiry Contact", "From: $email",  $name, $address, $telephone, $enquiry, $websearch, $recommended, $mag_ad, $flyer);

header( "Location: http://www.example.com/thankyou.html" );

?>
Any ideas where I am going wrong...and also how to secure it from spamming?

Many thanks!!!
Cerilia is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Old 04-23-2008, 11:13 AM   #2 (permalink)
TSF Enthusiast
 
jamiemac2005's Avatar
 
Join Date: Jul 2007
Location: Northampton, UK
Posts: 571
OS: Win Vista Home Premium & Ubuntu Hardy(8.04)


Re: Driving me crazy!

in the html you use the id "contactform" multiple times, i'm sure thats not correct usage, it may work but i thought an id was supposed to be unique...

i'm sorry i can't remember a lot of PHP so i don't know the problem, when you do get it sorted though you could start to stop spamming using basic javascript on your html page:

change
<input type="submit" value="Submit" />

to

<input type="submit" value="Submit" onSubmit="this.disabled=true;" />

i think .disabled is the property, (the button should grey out after having been clicked)
so that when one set of information has been submitted the user can not re-submit the data without having re-loaded the page first.
This will only stop people from clicking the submit button a million times when the page loads slowly (and submitting the data millions of times).

On the PHP side of things i don't know what you'd do to stop spamming, but i'm sure contact/query boxes aren't spammed a lot are they?

Hope any of this helped,
Jamey
jamiemac2005 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Old 04-23-2008, 05:40 PM   #3 (permalink)
Registered User
 
Join Date: Apr 2008
Location: Oklahoma City
Posts: 26
OS: xp(sp2), OSX(10.5)


Re: Driving me crazy!

yes ids should be unique, if you are doing this for css style then replace id="contactform" with class="contactform" in the html and change the declaration from #contactform{} to .contactform{} in the css. I have bearly looked at php but two things I would check are first do you have smtp setup on the server (or what ever it uses) and a variable is enclosed in quotes in mail(), you may have to concatenate the string with the variable.
snowman7000 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Old 04-23-2008, 11:12 PM   #4 (permalink)
Registered User
 
Cerilia's Avatar
 
Join Date: Apr 2008
Location: England
Posts: 11
OS: XP Pro SP2


Re: Driving me crazy!

Thanks guys for your advice... but concerning the PHP can you explain in simpler terms, as I have no idea what you are talking about. lol
Cerilia is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Old 04-24-2008, 04:10 AM   #5 (permalink)
Registered User
 
Cerilia's Avatar
 
Join Date: Apr 2008
Location: England
Posts: 11
OS: XP Pro SP2


Re: Driving me crazy!

Ok I did a search on these boards in an attempt to get the correct code in place... I have however come up against a problem (not the one that doesn't make it work, that still exists!) I dont know how to incorporate any of the other fields I've got...'how did they hear about us' fields!

I know I shouldn't expect a message as such, but an email at the least!

Anyone????

Current HTML with previous advice taken.

Code:
<form id="rwform" method="post" action="sendmail.PHP">

<div class="contactform">
<label for="name">Name</label>
<input  type="text" name="name" value="" />
</div>

<div class="contactform">
<label for="address">Address</label>
<input type="text" name="address" value="" />
</div>

<div class="contactform">
<label for="telephone">Telephone</label>
<input type="text" name="telephone" value="" />
</div>

<div class="contactform">
<label for="email">Email Address:</label>
<input  type="text" name="email" value="" />
</div>

<div class="contactform">
<label for="enquiry">Enquiry:</label>
<textarea name="enquiry" id="enquiry" rows="5" cols="25"></textarea>
</div>

<div class="contactform">
<label for="hearaboutus">How did you hear about us?</label>
<input type="checkbox" name="websearch" /> Web Search<br />
<input type="checkbox" name="recommended" class="threepxfix" /> Recommended<br />
<input type="checkbox" name="mag_ad" class="threepxfix" /> Magazine Advert<br />
<input type="checkbox" name="flyer" class="threepxfix" /> Flyer<br />
</div>
<div style="margin-left: 150px;">
<input type="submit" value="Submit" onSubmit="this.disabled=true;" /> <input type="reset" value="reset" />
</div>

</form>
New Code as found on this forum: 'Including comments'
Code:
<?php
// THESE ARE THE VARIABLES THAT YOU NEED TO EDIT!

$sendto = "myemail@host.co.uk"; // for example: username@usershost.com
$gotopage = "http://www.example.com/thankyou.html"; // for example: http://www.yoursite.com/thankyou.html

// end editable variables


  $_POST = array_map('strip_tags', $_POST);
  $name = $_POST['name'];
  $email = $_POST['email'];
  $message = $_POST['message'];
  
// let's format them
  $message = "Enquiry:" . "\n\n" . $message;
  $subject = "Email From Website - " . $name;

// this will show you who it's from AND will blind carbon-copy the message to them
  $headers .= 'From: ' . $name . '<' . $email . '>' . "\r\n";
  $headers .= 'Bcc: ' . $name . '<' . $email . '>' . "\r\n";

// let's check if that email is valid or not!
// if it's valid - send the email

        mail($sendto, $subject, $message, $headers);
        header("Location: $gotopage");

?>

Last edited by Cerilia : 04-24-2008 at 04:18 AM.
Cerilia is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Old 04-24-2008, 09:38 PM   #6 (permalink)
Design Team Member
 
Redcore's Avatar
 
Join Date: Aug 2007
Location: Jamestown, CA
Posts: 468
OS: WinXP

My System

Send a message via AIM to Redcore Send a message via MSN to Redcore Send a message via Yahoo to Redcore
Re: Driving me crazy!

No big deal - you're just learning...and you're doing fine. I did notice that last PHP script was a chopped up version of mine :P

The biggest part you did wrong in your first script was not putting all of your form elements together to create the message.

PHP Code:
mail("myaddress@mail.co.uk""Web Enquiry Contact""From: $email",  $name$address$telephone$enquiry$websearch$recommended$mag_ad$flyer); 
I'm sure you realize there are too many fields in there and it's not set up correctly - but you're learning and 95% of learning PHP comes from trial and error. :)

Here's what I have come up with. I tested it out, should work for you.
PHP Code:
// THESE ARE THE VARIABLES THAT YOU NEED TO EDIT!
$sendto "redcore@gmail.com"// for example: username@usershost.com
$gotopage "http://www.example.com/thankyou.html"// for example: http://www.yoursite.com/thankyou.html
// end editable variables

// initialize posted variables - not always necessary, but a good practice
$_POST array_map('strip_tags'$_POST);
$name $_POST['name'];
$address $_POST['address'];
$telephone $_POST['telephone'];
$email $_POST['email'];
$enquiry $_POST['enquiry'];
$websearch $_POST['websearch'];
$recommended $_POST['recommended'];
$mag_ad $_POST['mag_ad'];
$flyer $_POST['flyer'];

// this is advanced: formatting the "heard about us" option - you don't need to know this
$list "";
if(
$websearch=="on"){$list .= "Web Search+";}
if(
$recommended=="on"){$list .= "Recommendation+";}
if(
$mag_ad=="on"){$list .= "Magazine Ad+";}
if(
$flyer=="on"){$list .= "Flyer+";}
$list substr($list0, -1);
$list str_replace("+"", "$list);

// we have to compile all of our variables into a message
$message "Sent By: " $name "\n";
$message .= "Address: " $address "\n";
$message .= "Telephone: " $telephone "\n";
$message .= "Email: " $email "\n";
$message .= "Heard About Us Through: " $list "\n";
$message .= "\n";
$message .= "Enquiry:" "\n" $enquiry;

// put subject together
$subject "Email From Website - " $name;

// this will show you who it's from AND will blind carbon-copy the message to them
$headers 'From: ' $name '<' $email '>' "\r\n";
$headers .= 'Bcc: ' $name '<' $email '>' "\r\n";

// send the mail
mail($sendto$subject$message$headers);
//header("Location: $gotopage"); 
Notice how I combined all of those "$message" variables? The "." stands for "and" - so ".=" obviously stands for "and equals" ... you're just adding them all together with that.

Don't worry about not knowing what things mean in this...that's why I'm here...I can explain anything you need clarification on. I try to keep the scripts I post here simple - but sometimes I have to put something a bit more complex, so don't feel that you're supposed to know how to do any of it :P
__________________
Free Resources
PC Protection - Comodo Firewall | AVG Anti-Virus | WinPatrol | Ad-Aware | Spybot S&D | SpywareBlaster |
Web Design/Programming - KompoZer
(Editor) | Paint.NET (Graphic) | GIMP+GIMPShop (Graphic) | FileZilla (FTP Client) | Free Hosting |
Redcore is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Old 04-25-2008, 12:32 AM   #7 (permalink)
Registered User
 
Cerilia's Avatar
 
Join Date: Apr 2008
Location: England
Posts: 11
OS: XP Pro SP2


Re: Driving me crazy!

Redcore I am indebted, many many thanks...

But after uploading your code I still cant receive any feedback emails (Yes I did change addresses )!

Now I have trawled through my hosts vast database of support questions and I found this. Can I assume that in merely place this code;

Code:
Sendmail Functions
What is the path to Sendmail?

/usr/sbin/sendmail -fuser\@domainname.co.uk

You need to replace -fuser\@domainname.co.uk with a valid mailbox on your account:
ie -froot\@yourdomain.co.uk

You must leave in the -f and make sure there is a \ before the @

An example of how to use this is displayed below:
mail($to, $sub, $mess, "From: root@yourdomain.co.uk", "-froot@yourdomain.co.uk");
In this section?

Code:
// send the mail
mail($sendto, $subject, $message, $headers, * Place code here? *);
//header("Location: $gotopage");
Cerilia is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Old 04-25-2008, 05:06 PM   #8 (permalink)
Design Team Member
 
Redcore's Avatar
 
Join Date: Aug 2007
Location: Jamestown, CA
Posts: 468
OS: WinXP

My System

Send a message via AIM to Redcore Send a message via MSN to Redcore Send a message via Yahoo to Redcore
Re: Driving me crazy!

That shouldn't affect it sending out. I tested with the email "nobody@nowhere.com"
__________________
Free Resources
PC Protection - Comodo Firewall | AVG Anti-Virus | WinPatrol | Ad-Aware | Spybot S&D | SpywareBlaster |
Web Design/Programming - KompoZer
(Editor) | Paint.NET (Graphic) | GIMP+GIMPShop (Graphic) | FileZilla (FTP Client) | Free Hosting |
Redcore is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Old 04-28-2008, 11:24 AM   #9 (permalink)
Registered User
 
Cerilia's Avatar
 
Join Date: Apr 2008
Location: England
Posts: 11
OS: XP Pro SP2


Re: Driving me crazy!

Thanks again Redcore....but is everything working when you test it? I am still getting no joy this end!
Cerilia is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Old 04-29-2008, 04:23 PM   #10 (permalink)
Design Team Member
 
Redcore's Avatar
 
Join Date: Aug 2007
Location: Jamestown, CA
Posts: 468
OS: WinXP

My System

Send a message via AIM to Redcore Send a message via MSN to Redcore Send a message via Yahoo to Redcore
Re: Driving me crazy!

Yeah, it worked flawlessly on my server. Could you send me the actual page you got that reference from above? I don't think that should affect the server sending a message, but I can look into it more.
__________________
Free Resources
PC Protection - Comodo Firewall | AVG Anti-Virus | WinPatrol | Ad-Aware | Spybot S&D | SpywareBlaster |
Web Design/Programming - KompoZer
(Editor) | Paint.NET (Graphic) | GIMP+GIMPShop (Graphic) | FileZilla (FTP Client) | Free Hosting |
Redcore is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Old 04-30-2008, 03:36 AM   #11 (permalink)
Registered User
 
Cerilia's Avatar
 
Join Date: Apr 2008
Location: England
Posts: 11
OS: XP Pro SP2


Re: Driving me crazy!

Well surprise, surprise it worked when I added that code! Weird!

I have a problem though, the thank you page is not displaying? The address is correct, so what am I missing?
Cerilia is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Old 04-30-2008, 05:19 AM   #12 (permalink)
Registered User
 
Cerilia's Avatar
 
Join Date: Apr 2008
Location: England
Posts: 11
OS: XP Pro SP2


Re: Driving me crazy!

Sorry Redcore....I cant edit the above message. It seems I didn't add a space... added and now works perfectly.

Thank you Redcore for all your help. You are a credit to this forum.

Cheers!
Cerilia is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Old 04-30-2008, 08:17 AM   #13 (permalink)
Registered User
 
Cerilia's Avatar
 
Join Date: Apr 2008
Location: England
Posts: 11
OS: XP Pro SP2


Re: Driving me crazy!

oops nope this is weird...it doesn't work in Firefox but does in IE?
Cerilia is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Old 05-01-2008, 04:45 PM   #14 (permalink)
Design Team Member
 
Redcore's Avatar
 
Join Date: Aug 2007
Location: Jamestown, CA
Posts: 468
OS: WinXP

My System

Send a message via AIM to Redcore Send a message via MSN to Redcore Send a message via Yahoo to Redcore
Re: Driving me crazy!

What doesn't work - the form, the emailing, or the thank you page?
__________________
Free Resources
PC Protection - Comodo Firewall | AVG Anti-Virus | WinPatrol | Ad-Aware | Spybot S&D | SpywareBlaster |
Web Design/Programming - KompoZer
(Editor) | Paint.NET (Graphic) | GIMP+GIMPShop (Graphic) | FileZilla (FTP Client) | Free Hosting |
Redcore is offline  
Digg this Post!