 |
05-08-2008, 08:30 PM
|
PHP form
|
Posts: 1,471
Name: carl
Location: UK
|
I have managed to get XAMP working (thanks Andrei) so I can test PHP scripts and the form I asked about previously doesn't seem to work.
I am getting errors
Quote:
Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\xampp\htdocs\sendmail.php on line 12
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\sendmail.php:12) in C:\xampp\htdocs\sendmail.php on line 13
|
The form is HTML and the form handler is a very simple php script which I am still learning. I dont know where the php is going wrong and could use a little (or a lot!) of help.
The form code is
HTML Code:
<form id="form1" name="form1" method="post" action="sendmail.php">
<label for="Name">Full Name</label>
<input type="text" name="Name" id="Name" />
<label for="PhoneNo">Home Phone</label>
<input type="text" name="PhoneNo" id="PhoneNo" />
<label for="MobileNo">Mobile Phone</label>
<input type="text" name="MobileNo" id="MobileNo" />
<label for="Email">Email Address</label>
<input type="text" name="Email" id="Email" />
<label for="PropVal">Property Value <br />
<span class="Formsmallprint">If secured finance is required</span></label>
<input type="text" name="PropVal" id="PropVal" />
<label for="LoanAmount">Amount Required<br />
<span class="Formsmallprint">If secured finance is required</span></label>
<input type="text" name="LoanAmount" id="LoanAmount" />
<label for="debtHelp">Total value of Debt<br />
<span class="Formsmallprint">If debt help is required</span></label>
<input type="text" name="debtHelp" id="debtHelp" />
<label for="FinType">How can we help</label>
<select name="FinType" id="FinType">
<option selected="selected">Please Select</option>
<option value="mortgage">Mortgage</option>
<option value="remortgage">Remortgage</option>
<option value="secured">Secured Loan</option>
<option value="debtconsol">Debt Consolidation</option>
<option value="debt_man">Debt Management</option>
<option value="iva">IVA</option>
<option value="BTL">Buy to Let</option>
<option value="commercial">Commercial</option>
<option value="other">Other</option>
</select>
<label for="callaT">Best Time to Call</label>
<select name="callaT" id="callaT">
<option>Please Select</option>
<option value="morning">Morning</option>
<option value="afternoon">Afternoon</option>
<option value="evening">Evening</option>
<option value="any">Any time</option>
</select>
<input type="submit" name="submit" id="submit" value="Call me back" />
<a href="javascript:newwindow()" ><br />
Data Protection Statement</a>
</form>
(please ignor the javascript bit)
The PHP is
PHP Code:
<?php $name = $_REQUEST['Name'] ; $homePhone = $_REQUEST['PhoneNo'] ; $mobileNumber = $_REQUEST['MobileNo'] ; $email = $_REQUEST['Email'] ; $propertyValue = $_REQUEST['PropVal'] ; $loanRequired = $_REQUEST['LoanAmount']; $debtsAmount = $_REQUEST['debtHelp'] ; $FinanceType = $_REQUEST['FinType'] ; $CallaT = $_REQUEST['callaT'] ; mail( "my@email.co.uk", "Enquiry Form Results", "New Web Enquiry From:" $Name ); header( "Location: www.mysite.co.uk/thank_you.html" ); ?>
I think the problems are with
Quote:
mail( "my@email.co.uk", "Enquiry Form Results",
"New Web Enquiry From:" $Name );
|
which I thought would email me the form results
and
Quote:
|
header( "Location: www.mysite.co.uk/thank_you.html" );
|
which I thought would redirect the user to a thank you page
Can anyone shed any light on this please.
Last edited by bakerc : 05-08-2008 at 08:34 PM.
|
|
|
|
05-08-2008, 09:13 PM
|
Re: PHP form
|
Posts: 4
|
You need an SMTP (outgoing mail) server set up to use PHP's mail() function.
|
|
|
|
05-08-2008, 09:44 PM
|
Re: PHP form
|
Posts: 1,471
Name: carl
Location: UK
|
I should have posted this as the sendmain.php file, sorry
PHP Code:
<?php $yourwebsite = 'www.mysite.co.uk'; $subject='Reply Form'; $recipient_email='enq@mysite.co.uk'; $header = "From: $Name \r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-Type: text/html; charset=iso-8859-1\r\n"; $content= "Dear Carl, <p>" . $_GET['Name'] . " has responded to website. <b>Details:</b><p> Name is................. " . $_GET['Name'] . "<p> Home Phone number is.... " . $_GET['PhoneNo'] . "<p> Mobile Phone number is.. " . $_GET['MobileNo'] . "<p> Email address is........ " . $_GET['Email'] . "<p> Property Value.......... " . $_GET['PropVal'] . "<p> Loan Amount is.......... " . $_GET['LoanAmount'] . "<p> Property Value is....... " . $_GET['PropVal'] . "<p> Debts amount is......... " . $_GET['debtHelp'] . "<p> Finance Type is......... " . $_GET['FinType'] . "<p> The best time to call is " . $_GET['callaT'] . "<p> <hr noshade=\"true\" size=\"1\" color=\"#000000\" />"; mail($recipient_email, $subject, $content, $header); header( "Location: http://www.mysite.co.uk/thank_you.html" ); ?>
I am still getting
Quote:
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\sendmail.php on line 26
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\sendmail.php:26) in C:\xampp\htdocs\sendmail.php on line 29
|
Line 26 is
Quote:
|
mail($recipient_email, $subject, $content, $header);
|
Line 29 doesn't have anything on it?
The outgoing SMTP server port is 25, and I dont know what is meant by can't modify header. I thought the header line would redirect the users browser to the thank you page.
Could these errors have somthing to do with how I have XAMP set up?
Again - thanks for any help
Last edited by bakerc : 05-08-2008 at 09:55 PM.
|
|
|
|
05-09-2008, 02:24 AM
|
Re: PHP form
|
Posts: 656
|
You might be having a bit of a problem with your predefined variables. Generally speaking, for a registration form like this, you're almost always going to want to use $_POST. Right now you have $_REQUEST, which means that the information could come from either the URL or from the form. I would recommend always using either $_POST or $_GET and never using $_REQUEST. It isn't very often that you aren't going to know where you are getting your data from. In the case of the second script you posted, you might be getting some of your errors because you are using the $_GET instead of the $_POST (because your form's action is set to post).
As a security matter, you should also check each input to make sure it's the kind of data you want. In this form, someone could type all sorts of information that doesn't match the field in which it was typed. For instance, without any sort of validation, I could type in "green bean" for an email address and this script wouldn't know any better. It becomes even more of a security problem if you were using this form to load information into the database. Using SQL injection, a malicious user could erase or manipulate your database at will. It's a good habit to always validate user entered data from the beginning. Never trust user input.
For your header problems, take a look at this page. It seems like it's a fairly common problem. As you're learning PHP, I'd recommend several things. If you get an error and can't figure out what's causing it, paste the error code, minus the file path and line number into Google. I've found a lot of fixes that way. Another suggestion is to keep a dictionary of your error code messages and what you did to fix them. You won't need it after a while, but it can be a handy reference. Finally, the documentation at php.net is invaluable once you learn how to use it. The comments after the documentation can sometimes be even more helpful.
For your mailing problem, I'm not quite sure what the problem is because I've never compiled PHP yet. You might have to enable the mail server in your php.ini file. A quick search should bring something useful, but if not, look at the docs for XAMP and PHP.
Hope that helped.
|
|
|
|
05-09-2008, 08:30 AM
|
Re: PHP form
|
Posts: 1,471
Name: carl
Location: UK
|
Thanks for the reply VM
I have checked the SMTP and they seem fine, the propblem seems to be with the php which is little surprise because I am trying to learn as I go.
I have ready through the links you posted and tried changing a few things, I did copy and past the errors into google before posting here - what came up in google didn't make much sense but I tried a few things (like removing the ....., making sure the ; was there and a few other things but I reacon I must have upset the php gods or something because nothing works.
I have altered the code and took out a few things
PHP Code:
<?php $yourwebsite = 'www.bakerfinancial.co.uk'; $subject='Reply Form'; $recipient_email='enq@bakerfinancial.co.uk'; $header = "From: $Name \r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-Type: text/html; charset=iso-8859-1\r\n"; $content= "Dear Carl, you have a new web enquiry" ; Name is " . $_POST['Name'] . "<p> ; Home Phone number is " . $_POST['PhoneNo'] . "<p> ; Mobile Phone number is " . $_POST['MobileNo'] . "<p> ; Email address is " . $_POST['Email'] . "<p> ; Property Value is " . $_POST['PropVal'] . "<p> ; Loan Amount is " . $_POST['LoanAmount'] . "<p> ; Debts amount is " . $_POST['debtHelp'] . "<p> ; Finance Type is " . $_POST['FinType'] . "<p> ; Please call me in the " . $_POST['callaT'] . "<p> ; <hr noshade="true\" size=\"1\" color=\"#000000\" />"; mail($recipient_email, $subject, $content, $header); header( "Location: http://www.bakerfinancial/thank_you.html" ); ?>
I honestly have no idea whats going wrong and the more I read the more I think its something very easy to fix but I have changed all sorts of things re-tried and keep getting the same errors - does anyone have any idea whats wrong?
Last edited by bakerc : 05-09-2008 at 08:33 AM.
|
|
|
|
05-09-2008, 10:45 AM
|
Re: PHP form
|
Posts: 656
|
Looking at it again, I can see why you're probably having problems. Look at the way you're trying to create $content. After every line, you're ending it with a semicolon, but you aren't concatenating the values like you did with $header. If you remove all your semicolons for $content (except for the last one), I have a feeling it might work, solving both the headers already sent error and the email error.
Quote:
Originally Posted by bakerc
PHP Code:
<?php $yourwebsite = 'www.bakerfinancial.co.uk'; $subject='Reply Form'; $recipient_email='enq@bakerfinancial.co.uk'; $header = "From: $Name \r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-Type: text/html; charset=iso-8859-1\r\n"; $content= "Dear Carl, you have a new web enquiry" ; Name is " . $_POST['Name'] . "<p> ; Home Phone number is " . $_POST['PhoneNo'] . "<p> ; Mobile Phone number is " . $_POST['MobileNo'] . "<p> ; Email address is " . $_POST['Email'] . "<p> ; Property Value is " . $_POST['PropVal'] . "<p> ; Loan Amount is " . $_POST['LoanAmount'] . "<p> ; Debts amount is " . $_POST['debtHelp'] . "<p> ; Finance Type is " . $_POST['FinType'] . "<p> ; Please call me in the " . $_POST['callaT'] . "<p> ; <hr noshade="true\" size=\"1\" color=\"#000000\" />"; mail($recipient_email, $subject, $content, $header); header( "Location: http://www.bakerfinancial/thank_you.html" ); ?>
I honestly have no idea whats going wrong and the more I read the more I think its something very easy to fix but I have changed all sorts of things re-tried and keep getting the same errors - does anyone have any idea whats wrong?
|
|
|
|
|
05-09-2008, 10:52 AM
|
Re: PHP form
|
Posts: 1,471
Name: carl
Location: UK
|
Hi VM
Thanks for the reply.
I tried that, so the code looks like this...
PHP Code:
<?php header( "Location: C:\xampp\htdocs\thank_you.html" ); $yourwebsite = 'www.mysite.co.uk'; $subject='Reply Form'; $recipient_email='enq@mysite.co.uk'; $header = "From: $Name \r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-Type: text/html; charset=iso-8859-1\r\n"; $content= "Dear Carl, you have a new web enquiry" Name is " . $_POST['Name'] . "<p> Home Phone number is " . $_POST['PhoneNo'] . "<p> Mobile Phone number is " . $_POST['MobileNo'] . "<p> Email address is " . $_POST['Email'] . "<p> Property Value is " . $_POST['PropVal'] . "<p> Loan Amount is " . $_POST['LoanAmount'] . "<p> Debts amount is " . $_POST['debtHelp'] . "<p> Finance Type is " . $_POST['FinType'] . "<p> Please call me in the " . $_POST['callaT'] . "<p> <hr noshade="true\" size=\"1\" color=\"#000000\" />"; mail($recipient_email, $subject, $content, $header); ?>
but I am still getting the same error, I have moved the header to the top of the code as from what I have read thats the best place to put it. Not too bothered about the header at the moment, just want to get the thing to submit the form - this is driving me crazy - I got HTML and CSS fairly easy but for some reason this is frying my brian.
I think I will spend the weekend learning php - or at least enough to make this work and validate. 
Last edited by bakerc : 05-09-2008 at 11:38 AM.
|
|
|
|
05-09-2008, 11:59 AM
|
Re: PHP form
|
Posts: 656
|
You still have to remove the last double quote from this line:
PHP Code:
$content= "Dear Carl, you have a new web enquiry"
If you look at the color of the text in this post, it should help. You want to have your quoted text in red and your variables in blue. For what you have here, most of it is opposite. If you don't have an editor that has syntax highlighting, there are several decent ones out there that are free: Notepad++, Komodo Edit, jEdit, etc. I use Dreamweaver mostly, and the colors vary a little bit from the way it is here, but the highlighting sure helps.
By the way, if you're looking for good tutorials online, I'd recommend http://www.tizag.com/. W3schools is good too. If you want a book, I'd recommend anything by Larry Ullman. I'm pretty sure you'll pick it up quickly because you seem really open to learning.
Last edited by VirtuosiMedia : 05-09-2008 at 12:02 PM.
|
|
|
|
05-09-2008, 01:36 PM
|
Re: PHP form
|
Posts: 1,471
Name: carl
Location: UK
|
Thanks again VM
I have gone through a few of the tutorials in the link you provided and there are fairly easy to follow. Calling it a day as I am frazzled!, should have the form working by Monday if not before, the syntax of the code I put up makes a lot more sense after reading just a couple of these tutorials.
It wont let me give you any TP until I spread some about so virtual or imaginary TP will have to do...
Cheers again
|
|
|
|
05-10-2008, 06:40 AM
|
Re: PHP form
|
Posts: 1,471
Name: carl
Location: UK
|
Been thinking about it and I want the form to be a little more interactive which would take me too long to lean (I dont do this for a profession and I don't really want to know everything about everything)
Just a thought but how much would it cost to have a form that can do the following.
HTML Code:
<form id="form1" name="form1" method="post" action="sendmail.php">
<label for="Name">Full Name</label>
<input type="text" name="Name" id="Name" />
<label for="PhoneNo">Home Phone</label>
<input type="text" name="PhoneNo" id="PhoneNo" />
<label for="MobileNo">Mobile Phone</label>
<input type="text" name="MobileNo" id="MobileNo" />
<label for="Email">Email Address</label>
<input type="text" name="Email" id="Email" />
<label for="PropVal">Property Value <br />
<span class="Formsmallprint">If secured finance is required</span></label>
<input type="text" name="PropVal" id="PropVal" />
<label for="LoanAmount">Amount Required<br />
<span class="Formsmallprint">If secured finance is required</span></label>
<input type="text" name="LoanAmount" id="LoanAmount" />
<label for="debtHelp">Total value of Debt<br />
<span class="Formsmallprint">If debt help is required</span></label>
<input type="text" name="debtHelp" id="debtHelp" />
<label for="FinType">How can we help</label>
<select name="FinType" id="FinType">
<option selected="selected">Please Select</option>
<option value="mortgage">Mortgage</option>
<option value="remortgage">Remortgage</option>
<option value="secured">Secured Loan</option>
<option value="debtconsol">Debt Consolidation</option>
<option value="debt_man">Debt Management</option>
<option value="iva">IVA</option>
<option value="BTL">Buy to Let</option>
<option value="commercial">Commercial Mortgage</option>
<option value="other">Other</option>
</select>
<label for="callaT">Best Time to Call</label>
<select name="callaT" id="callaT">
<option>Please Select</option>
<option value="morning">Morning</option>
<option value="afternoon">Afternoon</option>
<option value="evening">Evening</option>
<option value="any">Any time</option>
</select>
<input type="submit" name="submit" id="submit" value="Call me back" />
<a href="javascript:newwindow()" ><br />
Data Protection Statement</a>
</form>
Can anyone give me an idea of how much it woud cost to have a form with the fields above but for the monetary input and label to change for the user depending on what service they select.
After they have selected one of the following
HTML Code:
<select name="FinType" id="FinType">
<option selected="selected">Please Select</option>
<option value="mortgage">Mortgage</option>
<option value="remortga | |