Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Problems getting form script to work
Old 05-04-2010, 03:17 PM Problems getting form script to work
Average Talker

Posts: 18
Name: Simon Harvey
Trades: 0
Hi

I cant seem to get my contact from script to work!!

Im hosting on Fasthost. My form action is '/htdocs/form/sendmail.php'.

My script is:
PHP Code:
<?php
$email_to
="form@iter-research.co.uk";
$name=$_POST["Name"];
$email_from=$_POST["form@iter-research.co.uk"];
$message=$_POST["Name,Address,Postcode,Email,Gender,Age,Correspondence"];
$email_subject="Consultation Form";
$headers=
"from:$email_from.\n";
"reply-to:$email_from.\n";

if(!
filter_var($email_fromFILTER_VALIDATE_EMAIL)) {
die(
"The email address entered is invalid.");
$message "Name: "$name "\r\nMessage: " $message;
ini_set("sendmail_from"$email_from);
$sent mail($email_to$email_subject$message$headers, -f$email_from);
if(
$sent) {
header("Location: http://www.iter-rese...hank_you.html/");

} else {
echo 
"There has been an error sending your message. Please try later.";
}
}
?>
When i hit the submit button the browser just trys to open a new window with my PHP script in.

I'm New to PHP and contact forms so if im doing something really basic and stupid i apologise in advance.

has anyone got any suggestion??

Simon
simonharvey71 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-04-2010, 05:28 PM Re: Problems getting form script to work
vangogh's Avatar
Post Impressionist

Latest Blog Post:
Why Responsive Design?
Posts: 10,815
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
Simon could you post the code for the page with the form as well and also let us know where that file is located? I think the problem will be on that page as it doesn't sound like sendmail.php is loading correctly.

A couple of thoughts.

1. Is php enabled on your server? If it is then you shouldn't be seeing the php script displayed. It's possible php isn't running on your server. You can test this by creating a new file. Call it info.php and all you need to place inside the file is the following line

<?php phpinfo(): ?>

Then navigate to the page you created in a browser. If php is enabled you should see all sorts of information about what version you're using and how it's been set up. If you see the line of code then it means php isn't enabled.

2. You shouldn't need to include htdocs in your form action. The root for your domain would be that folder so your action should probably be /form/sendmail.php

Try either or both of the above and if neither works share the code on the page with your form.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 05-05-2010, 03:40 PM Re: Problems getting form script to work
Average Talker

Posts: 18
Name: Simon Harvey
Trades: 0
Quote:
Originally Posted by vangogh View Post
Simon could you post the code for the page with the form as well and also let us know where that file is located? I think the problem will be on that page as it doesn't sound like sendmail.php is loading correctly.

A couple of thoughts.

1. Is php enabled on your server? If it is then you shouldn't be seeing the php script displayed. It's possible php isn't running on your server. You can test this by creating a new file. Call it info.php and all you need to place inside the file is the following line

<?php phpinfo(): ?>

Then navigate to the page you created in a browser. If php is enabled you should see all sorts of information about what version you're using and how it's been set up. If you see the line of code then it means php isn't enabled.

2. You shouldn't need to include htdocs in your form action. The root for your domain would be that folder so your action should probably be /form/sendmail.php

Try either or both of the above and if neither works share the code on the page with your form.
I host with fasthost and when i check out my dashboard the PHP box is already ticked. so i asume it is enabled, though you know what happens when you assume...

I set up the info.php file and when i navigated to it i just got a blank page, which looks bad i guess??

i have changed the path of the php file to /form/sendmail.php.

Any ideas what to do next??

The form code is:
HTML Code:
<form action="form/sendmail.php" method="post" name="form1" id="form1">
        <table width="100%" border="0" cellspacing="0" cellpadding="3">
        <tr>
        <td width="38%"><label>
        <div align="right">Name</div>
        </label></td>
        <td width="62%"><input name="Name" type="text" id="Name" tabindex="1" size="50" /></td>
        </tr>
        <tr>
        <td><label>
        <div align="right">Address</div>
        </label></td>
        <td><textarea name="Address" cols="50" id="Address" tabindex="2"></textarea></td>
        </tr>
        <tr>
        <td><label>
        <div align="right">Postcode</div>
        </label></td>
        <td><input name="Postcode" type="text" id="Postcode" tabindex="3" /></td>
        </tr>
        <tr>
        <td><label>
        <div align="right">Email</div>
        </label></td>
        <td><input name="Email" type="text" id="Email" tabindex="4" size="50" /></td>
        </tr>
        <tr>
        <td><label>
        <div align="right">Gender</div>
        </label></td>
        <td><select name="Gender" size="1" id="Gender" tabindex="5">
        <option value="1">Male</option>
        <option value="2">Female</option>
        <option value="0" selected="selected">Please Select</option>
        </select></td>
        </tr>
        <tr>
        <td><label>
        <div align="right">Age</div>
        </label></td>
        <td><select name="Age" size="1" id="Age">
        <option value="0">Please Select</option>
        <option value="1">&lt;16</option>
        <option value="2">17-20</option>
        <option value="3">21-25</option>
        <option value="4">26-30</option>
        <option value="5">31-35</option>
        <option value="6">36-40</option>
        <option value="7">41-45</option>
        <option value="8">46-50</option>
        <option value="9">50&gt;</option>
        </select></td>
        </tr>
        <tr>
        <td><label>
        <div align="right">Would you prefer any further correspondence to be in Welsh Or English </div>
        </label></td>
        <td><select name="Correspondence" size="1" id="Correspondence">
        <option value="0">Please Select</option>
        <option value="1">Welsh</option>
        <option value="2">English</option>
        </select>
        <label>
        <input type="submit" name="Submit" value="Submit" />
        <input name="Reset" type="reset" id="Reset" value="Reset" />
        </label></td>
        </tr>
        </table>
    </form>
simonharvey71 is offline
Reply With Quote
View Public Profile
 
Old 05-05-2010, 04:07 PM Re: Problems getting form script to work
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
U need to find out if PHP works to start with..

What about a file named test.php

with just
<?php
echo "Testing123";

?>

Does it just say Testing123 or does it have teh rest of teh code or nothing )
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 05-05-2010, 04:30 PM Re: Problems getting form script to work
Average Talker

Posts: 18
Name: Simon Harvey
Trades: 0
ive put <?php echo 'It supports PHP'; ?> into a file and it echoed 'it supports PHP' so it looks like PHP is enabled on my account.
simonharvey71 is offline
Reply With Quote
View Public Profile
 
Old 05-05-2010, 07:40 PM Re: Problems getting form script to work
Marik's Avatar
Skilled Talker

Posts: 99
Trades: 0
I didn't look through your code, but you can just use this one I made. It works (I think ):


Code:
<style type="text/css">
body {
    font-family: arial;
}
.contactForm {
    border: 1px solid #ccc;
    padding: 15px;
    margin: auto;
}
.contactForm td {
    padding: 0 55px 10px 0;
}
h1 {
    font-size: 23px;
    margin: 0;
}
.text {
    border: 1px solid #999;
    width: 260px;
    height: 25px;
}
textarea {
    border: 1px solid #999;
    width: 420px;
    height: 200px;
}
.error {
    color: #f00;
    font-size: 13px;
    font-weight: bold;
}
</style>
PHP Code:
<?php

// turn off error reporting
error_reporting(0);

// user submitted form variables
$name    $_POST['name'];
$email   $_POST['email'];
$subject $_POST['subject'];
$message $_POST['message'];
$submit  $_POST['submit'];

if(isset(
$submit)) {

    if(!
$name)
        
$error1 "<span class='error'>Required: Name</span><br />";
    if (!
$email)
        
$error2 "<span class='error'>Required: Email</span><br />";
    if(
strpos($email'@') == 0)
        
$error3 "<span class='error'>Invalid Email</span><br />";
    if(!
$subject)
        
$error4 "<span class='error'>Required: Subject</span><br />";
    if(!
$message)
        
$error5 "<span class='error'>Required: Message</span><br />";

    if(
strpos($email'@') == 1) {

        if(
$name && $email && $subject && $message) {
            
// send email
            
$sendMail mail("ENTER - YOUR - EMAIL - HERE"$subject$message"from: $email");

            
// display success or fail message
            
if($sendMail)
                echo 
"<div style='border:2px solid green;width:300px;margin:auto;margin-bottom:25px;text-align:center;padding:5px;'>Your message has been sent.</div>";
            else
                echo 
"<div style='border:2px solid red;width:300px;margin:auto;margin-bottom:25px;text-align:center;padding:5px;'>Message could not be sent.</div>";

        }

    }

}

?>
HTML Code:
<form action="" method="POST">
<table class="contactForm">
    <tr>
        <td>&nbsp;</td>
        <td><h1>Contact Us</h1></td>
    </tr>
    <tr>
        <td><label>Name:</label></td>
        <td><?php echo $error1; ?><input type="text" class="text" name="name" value="<?php echo $name; ?>" /></td>
    </tr>
    <tr>
        <td><label>Email:</label></td>
        <td><?php echo $error2; ?><?php echo $error3; ?><input type="text" class="text" name="email" value="<?php echo $email; ?>" /></td>
    </tr>
    <tr>
        <td><label>Subject:</label></td>
        <td><?php echo $error4; ?><input type="text" class="text" name="subject" value="<?php echo $subject; ?>" /></td>
    </tr>
    <tr>
        <td><label>Message:</label></td>
        <td><?php echo $error5; ?><textarea name="message"><?php echo $message; ?></textarea></td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td><input type="submit" name="submit" value="Send Message" /></td>
    </tr>
</table>
</form>
Just replace "ENTER - YOUR - EMAIL - HERE" with your email address

BTW I didn't add any filtering to sanitize input from the user, you may want to add that for security reasons especially if this is going to insert the emails into a database in addition to mailing them to you.

Last edited by Marik; 05-05-2010 at 07:46 PM..
Marik is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Problems getting form script to work
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25589 seconds with 12 queries