Forum Moderators: coopster

Message Too Old, No Replies

Can't get my PHP script to work

Won't work...

         

jumjum

3:01 pm on Jul 14, 2010 (gmt 0)

10+ Year Member


I can't seem to get my PHP script to work. There's probably an error somewhere as this is my first time using it. Am I using the correct format? This code is for a business. I'm using HTML 4.0.

My PHP code:

<?php $sendTo = "Blah@blah.com";
$subject = "Order from Blah";
$name = $_POST['name'];
$email = $_POST['email'];
$Blah = $_POST;['blah'];
$Blah2 = $_POST;['blah2'];

mail($sendTo,$subject,$name,$email,$Blah,$Blah2);
?>



My form code:

<form method="post" action="neofanatic@live.com" enctype="text/plain">
<p class="legend"><b><u>General information</u></b></p>
<fieldset id="general">
<label>Name:</label><input type="text" name="name" size="30" /> <br />
<label>Email:</label><input type="text" name="email" size="50" /> <br />

</fieldset>

<p class="legend"><b><u>Purchases</u></b></p>
<fieldset id="purchases">
<table width="80%" border="0" cellpadding="0" cellspacing="0">
<p id="extras"><label><u>Blah 1</u></label><ol><input type="checkbox" name="Blah" value="Blah" />Blah blah blah - <label>Qty:</label><input type="text" name="blah2" size="2" /> <br /> etc. etc.

My format is each line has a checkbox and a quantity box.

optik

3:06 pm on Jul 14, 2010 (gmt 0)

10+ Year Member



needs to be mail($sendTo,$subject,"$name,$email,$Blah,$Blah2");

jumjum

3:14 pm on Jul 14, 2010 (gmt 0)

10+ Year Member



Will the PHP script still work even if I don't have the HTML file published on the internet?

I'm still not receiving the mail. Thanks for your effort to help. Should I use $_POST or $_REQUEST if I know that some of the boxes will be left empty?

StoutFiles

3:17 pm on Jul 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your PHP code will never work if the file is still an HTML file. The extension needs to be changed from .html to .php for the server to know it has to parse code.

jumjum

3:23 pm on Jul 14, 2010 (gmt 0)

10+ Year Member



The form is in file #*$!xx.html
And the PHP script is on a file emailform.php.

For example, if I filled in the form by going C://Documents and settings etc. in the browser and submitted it, if it was correct, would it still go to my email even though the HTML/PHP files aren't published on the internet?

BarryStCyr

4:43 pm on Jul 14, 2010 (gmt 0)

10+ Year Member



If you don't publish them to the a server, what's going to run your script?

rainborick

5:21 pm on Jul 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You need to change the action attribute in the <form> tag on your HTML page to "emailform.php" in order for the data to be sent to that script for mailing.

Matthew1980

7:07 pm on Jul 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there jumjum,

Welcome to the forum :) [webmasterworld.com ]

$subject = "Order from Blah";
$name = $_POST['name'];
$email = $_POST['email'];
$Blah = $_POST;['blah'];
$Blah2 = $_POST;['blah2'];


I'm surprised as the script works at all, especially with those syntax errors, replace the lines I have bolded with this:-

$Blah = $_POST['blah'];
$Blah2 = $_POST['blah2'];

You'll notice the missing ';' from the first quoted code.

Also with regards to the required & additional parameters read the specifics on php dot net:[uk.php.net ] This will detail on how to structure the mail function. And use this:[w3schools.com ] as a guide to see what you need to do, because potentially without correct formatting, you could send an email with all the detail on one single line!

And as a few people have already commented you need to set the form attributes correctly, & make sure that you have the file name typed correctly into the action="" declaration; and make sure that the file extension for any php application is .php or the parser will not react to the <?php?> tags & code within them ;)

And once you get the form & email script functional (localhost testing) make sure that you sanitise the data (strip_tags() around the $_POST['somename'] superglobals) so that any data sent from the user can't be used maliciously.

[EDIT]: Just noticed too that your missing the closing </form> and a submit button, but whether you neglected to post that code or not...

Hope this helps you a little.

Cheers,
MRb