Forum Moderators: coopster

Message Too Old, No Replies

hi can any body help me with email script please

Parse error: syntax error, unexpected ',' in C:\wamp\www\emailphp.php on li

         

jimbob20th

8:35 pm on Mar 24, 2011 (gmt 0)

10+ Year Member



Hi there,
iam fairly new to php and struggling with a simple email script which has it input from a html form and evertime i press submit i get this message Parse error: syntax error, unexpected ',' in C:\wamp\www\emailphp.php on line 27


the code is
<?php
$name = $_POST['Name'];
$email = $_POST['email'];
$act = $_POST['Act'];
$telephone = $_POST['telephone'];
$description = $_POST['description'];
$age = $_POST['Age'];

$message .= "Name: \n";
$message .= $name;
$message .= "\n";
$message .= "email: \n";
$message .= $email;
$message .= "\n";
$message .= "Act: \n";
$message .= $act;
$message .= "\n";
$message .= "Telephone: \n";
$message .= $telephone;
$message .= "\n";
$message .= "description of the act: \n";
$message .= $description;
$message .= "\n";
$message .= "are you over 18: \n";
$message .= $age;

mail("email@mydomian.com"), 'Subject: '$message', 'From:' . $email);
Header("Location: index.html");
?>

Matthew1980

9:05 pm on Mar 24, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Jimbob20th,

Welcome to WebmasterWorld!

Your code should read something like this:-


<?php
//set error reporting level to ALL - a must when developing code
error_reporting(E_ALL)

//sanitise any user generated input first
$name = strip_tags($_POST['Name']);
$email = strip_tags($_POST['email']);
$act = strip_tags($_POST['Act']);
$telephone = strip_tags($_POST['telephone']);
$description = strip_tags($_POST['description']);
$age = strip_tags($_POST['Age']);

//build the message
$message = "Name: \n";
$message .= $name;
$message .= "\n";
$message .= "email: \n";
$message .= $email;
$message .= "\n";
$message .= "Act: \n";
$message .= $act;
$message .= "\n";
$message .= "Telephone: \n";
$message .= $telephone;
$message .= "\n";
$message .= "description of the act: \n";
$message .= $description;
$message .= "\n";
$message .= "are you over 18: \n";
$message .= $age;

mail("email@mydomian.com", "Subject: Submission", $message, "From:".$email);
Header("Location: index.html");
?>


Though not perfect, and certainly by no means secure, but this should get you going, you had an extra ) in the mail() that was confusing the parser! And were missing a parameter from the function too :)

Have a read of this [uk.php.net] too, this will help you understand this a little better...

Hope that makes sense.

Cheers,
MRb

jimbob20th

9:57 am on Mar 26, 2011 (gmt 0)

10+ Year Member



hi Matthew1980
thank alot for that everything seem be working ok now
cheers again jimbob20th

Matthew1980

10:08 am on Mar 26, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>>..everything seem be working ok now

Good to hear, though I strongly advise that you read up on data sanitizing so that you can employ this in your next version of this code, as it currently stands, this code can be exploited quite easily.

As a rule you should NEVER trust anything that a user is able to submit from a form INTO a mail function, you need to validate the email address, and ensure that only ONE address is present, you also need to filter out any tags (the function I added) and check that the int's being sent through are actually numerical.

I'm not trying to scare you, just trying to advise on what could potentially could happen if someone was to try and take advantage of the site, and it's email form.

Anyway, have fun with the rest of the project, and good luck.

Cheers,
MRb