Web Development Thread, Creating a form, web novice, help please in Coding and Web Development; I'm using dreamweaver CS5 and i've tried to adapt a helpful online tutorial to my needs, this is what i ...
-
30th June 2010, 10:44 AM #1 Creating a form, web novice, help please
I'm using dreamweaver CS5 and i've tried to adapt a helpful online tutorial to my needs, this is what i have come up with thus far:
Code:
<?php
//If the form is submitted
if(isset($_POST['submit'])) {
//Check to make sure that the name field is not empty
if(trim($_POST['contactname']) == '') {
$hasError = true;
} else {
$name = trim($_POST['contactname']);
}
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = '******************'; //Put your own email address here
$body = "Name: $name \n\n";
$headers = 'C3 Referral Form <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $body, $headers);
$emailSent = true;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>C3 Referral Form</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script src="jquery.validate.pack.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#contactform").validate();
});
</script>
<style type="text/css">
body {
font-family:Arial, Tahoma, sans-serif;
}
#contact-wrapper {
width:880px;
border:1px solid #e2e2e2;
background:#f1f1f1;
padding:20px;
}
#contact-wrapper div {
clear:both;
margin:1em 0;
}
#contact-wrapper label {
display:block;
float:none;
font-size:16px;
width:auto;
}
form#contactform input {
border-color:#B7B7B7 #E8E8E8 #E8E8E8 #B7B7B7;
border-style:solid;
border-width:1px;
padding:5px;
font-size:16px;
color:#333;
}
form#contactform textarea {
font-family:Arial, Tahoma, Helvetica, sans-serif;
font-size:100%;
padding:0.6em 0.5em 0.7em;
border-color:#B7B7B7 #E8E8E8 #E8E8E8 #B7B7B7;
border-style:solid;
border-width:1px;
}
</style>
</head>
<body>
<div id="contact-wrapper">
<p class="error"> </p>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform">
<div style="width:400px">
<label for="Name of Student"><strong>Name of Student:</strong></label>
<input type="text" size="50" name="contactname" id="contactname" value="" />
</div>
<div style="width:400px">
<label for="Tutor Group"><strong>Tutor Group:</strong></label>
<input type="text" size="50" name="Tutor Group" id="Tutor group" value="" />
</div>
<div style="width:400px">
<label for="Staff Member"><strong>Staff Member:</strong></label>
<input type="text" size="50" name="Staff member" id="Staff Member" value="" />
</div>
<div style="width:400px">
<label for="Date of Incident"><strong>Date of Incident:</strong></label>
<input type="text" size="50" name="Date of Incident" id="Date of incident" value="" />
</div>
<div style="width:400px">
<label for="Period"><strong>Period:</strong></label>
<input type="text" size="50" name="Period" id="Period" value="" />
</div>
<div style="width:400px">
<label for="Subject"><strong>Subject:</strong></label>
<input type="text" size="50" name="Subject" id="Subject" value="" />
</div>
<table width="740" height="227" border="1">
<tr>
<th width="40" height="62" scope="col"> </th>
<th width="59" scope="col">Rule Broken</th>
<th width="619" scope="col">Explanation of Incident</th>
</tr>
<tr>
<th height="89" scope="row">C1</th>
<td><textarea name="C1 Rule Broken" cols="10" rows="5" id="C1 Rule Broken"></textarea></td>
<td>
<textarea name="C1 Explanation" cols="100" rows="5" id="C1 Explanation"></textarea>
</td>
</tr>
<tr>
<th scope="row">C2</th>
<td><textarea name="C2 Rule Broken" cols="10" rows="5" id="C2 Rule Broken"></textarea></td>
<td><textarea name="C2 Explanation" cols="100" rows="5" id="C2 Explanation"></textarea></td>
</tr>
<tr>
<th scope="row">C3</th>
<td><textarea name="C3 Rule Broken" cols="10" rows="5" id="C3 Rule Broken"></textarea></td>
<td><textarea name="C3 Explanation" cols="100" rows="5" id="C3 Explanation"></textarea></td>
</tr>
</table>
<div style="width:400px">
<label for="Excat Time sent to BFL"><strong>Exact time sent to BfL:</strong></label>
<input type="text" size="50" name="Time Sent to BFL" id="Time Sent to BFL" value="" />
</div>
<div>
<label for="Signed"><strong>Signed:</strong></label>
<input type="text" size="50" name="Signed" id="Signed" value="" />
</div>
<p>
<input type="submit" value="Send Message" name="submit" />
</p>
</form>
</div>
</body>
</html> My problem is that it won't send any emails, i know that the top section of the php code definately needs adapting so that the body includes all my fields....i think (?) but first things first i want to get it to actually send an email so i can see what it looks like in the email, any help muccccccccccccccccchly appreciated
-
-
IDG Tech News
-
30th June 2010, 10:58 AM #2 Just to point out the bleeding obvious first, you have changed this line:
Code:
$emailTo = '******************'; //Put your own email address here
so that your email address is there rather than stars haven't you?
-
-
30th June 2010, 11:00 AM #3 Yea, i edited that out on purpose
-
-
30th June 2010, 11:08 AM #4 
Originally Posted by
mrbios
Yea, i edited that out on purpose

just checking 
First thing that pops to mind is that you're not giving the email a subject, as it's a web form I'd imagine you want this to be a constant so you can identify them in your inbox, so try this:
Code:
just before the 'mail()' line, add:
$subject="Email subject goes here";
Then alter your mail line like so:
mail($emailTo, $subject, $body, $headers);
-
-
30th June 2010, 11:16 AM #5 Cheers, ive added that in but still no email
As it's only going to be used internally is there any way i can do something like specifying the mail server and addresses to use for sending etc?
-
-
30th June 2010, 11:19 AM #6 PHP's mail function depends on its configuration in php.ini. On Windows, you should specify an SMTP server for it to use. On Linux/Unix, you need to specify the path to sendmail (or a sendmail-like program. Which in turn can be configured to send via SMTP or relay it directly).
-
-
30th June 2010, 11:21 AM #7 Ah ok, in this case im using Winows and it's hosted on IIS7
What do i need to edit in the php.ini?
-
-
30th June 2010, 11:24 AM #8 Do a search for SMTP, and you should find this area:
Code:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
Specify your favourite mail server hostname or IP address in there (replacing localhost in the example above). Ensure the SMTP server security/policies will accept and relay messages from your IIS host though.
-
-
30th June 2010, 11:30 AM #9 I'm just looking at your $headers variable and I think that might be causing the error, AFAIK you can't have custom information in the header.
Try changing the $headers variable to this:
Code:
$headers = "From: " . $emailTo . "\r\nReply-To: " . $emailTo;
-
-
30th June 2010, 11:35 AM #10 
Originally Posted by
webman
Do a search for SMTP, and you should find this area:
Code:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
Ok i think i've configured that correctly, i've also configured a custom SMTP connector to recieve mail from my web server, is that correct?
EDIT: cheers LosOjos i'll do that now
-
-
30th June 2010, 11:40 AM #11 Yes that should be it. Don't forget to restart the web server after making changes to php.ini.
-
-
30th June 2010, 11:44 AM #12 wohoo it emails
thank you both
Now then, give me 5 mins and i'll be back with my next problem
-
-
30th June 2010, 11:48 AM #13 Ok next problem i have then, i now want the information entered into each field of the form to go into the email but i want to be able to format the email into a nice layout that when printed out will look somewhat like the form does, is this possible and is it easy enough to achieve?
At the moment the email just emails me the word "Name:" and nothing else, i assume this is to do with the contents in the very beginning piece of code?
Last edited by mrbios; 30th June 2010 at 11:53 AM.
-
-
30th June 2010, 12:03 PM #14 The contents of the mail that is sent is stored in the $body variable. Presently, it is set to do very little:
Code:
$body = "Name: $name \n\n";
Taking that back a step or two, you first look at where $name is.
Code:
$name = trim($_POST['contactname']);
That retrieves the value of the form field named 'contactname', strips any leading/trailing whitespace and assigns it to the $name variable. You just need to add similar lines for your other fields.
In your form:
Code:
<input type="text" size="50" name="Tutor Group" id="Tutor group" value="" />
I would recommend changing the value of the "name" attribute to something without spaces and uppercase letters. E.g, tutor_group. Same goes for all other fields. Then:
Code:
$name = trim($_POST['contactname']);
$tutor_group = trim($_POST['tutor_group']);
...
$body = "Name: $name \n\n";
$body .= "Tutor group: $tutor_group\n\n";
...
So you just carry on adding to the $body variable with the appropriate fields.
-
-
30th June 2010, 12:28 PM #15 Cheers webman, does that php use the "id" part of the items or the "name" part of the items?
-
SHARE:
Similar Threads
-
By paul_1989 in forum Web Development
Replies: 3
Last Post: 28th March 2010, 11:20 PM
-
By RabbieBurns in forum How do you do....it?
Replies: 0
Last Post: 8th October 2008, 01:17 PM
-
By HodgeHi in forum Web Development
Replies: 17
Last Post: 5th November 2007, 12:29 PM
-
By Halfmad in forum Web Development
Replies: 12
Last Post: 2nd May 2007, 12:16 PM
-
By park_bench in forum Web Development
Replies: 2
Last Post: 24th January 2007, 10:18 AM
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules