Hey, I'm trying to get a form submit to work, I've got this made:


<?php
$to = "x" ;
$subject = "Application form" ;
$firstname = $_REQUEST ;
$charname = $_REQUEST ;
$class = $_REQUEST ;
$level = $_REQUEST ;
$age = $_REQUEST ;
$timezone = $_REQUEST ;
$raidavail = $_REQUEST ;
$mmoexp = $_REQUEST ;
$charlink = $_REQUEST ;
$s2_q1 = $_REQUEST ;
$s2_q2 = $_REQUEST ;
$s2_q3 = $_REQUEST ;
$s2_q4 = $_REQUEST ;
$s2_q5 = $_REQUEST ;
$s2_q6 = $_REQUEST ;
$s2_q7 = $_REQUEST ;
$s2_q8 = $_REQUEST ;
$s3_q1 = $_REQUEST ;
$s3_q2 = $_REQUEST ;
$s3_q3 = $_REQUEST ;
$s3_q4 = $_REQUEST ;
$s3_q5 = $_REQUEST ;
$s3_q6 = $_REQUEST ;
$s3_q7 = $_REQUEST ;
$headers = "From: $charname" ;

$sent = mail($to, $subject, $firstname, $charname, $class, $level, $age, $timezone, $raidavail, $mmoexp, $charlink, $s2_q1, $s2_q2, $s2_q3, $s2_q4, $s2_q5, $s2_q6, $s2_q7, $s2_q8, $s3_q1, $s3_q2, $s3_q3, $s3_q4, $s3_q5, $s3_q6, $s3_q7, $headers) ;

if($sent)
{print "Your mail was sent successfully"; }
else
{print "We encountered an error sending your mail"; }
?>

When it submits, I get this error:

Warning: mail() expects at most 5 parameters, 27 given in /home/content/v/a/l/valthonic/html/submitform.php on line 30

Looking over previous posts. I don't see any issue with it, someone posted this exact layout I just added to it, and its not working.. Anyone have a helpful tip to fix this?

Thank you.

Dani AI

Generated

Two separate issues are visible in the thread: the mail() usage and how the form values are being read/joined. was right that the message body must be a single string (not dozens of separate parameters), but the original form-code also had some basic mistakes that weren’t fixed yet.

The concrete problems to check:

  • The form values must be read with keys (for example $_POST['firstname'] or filter_input(...)). The original code used $_REQUEST with no index, which yields a syntax/logic problem.
  • Mail headers should contain an email address (many MTAs reject a plain name). Put the user’s name in the message and use a server sender for From: and the user address as Reply-To:.
  • Don’t concatenate raw user input into headers — strip CR/LF to prevent header injection.
  • For readable email bodies, build one message string (a heredoc is convenient) or concatenate with explicit separators; escape sequences like \n require double-quoted strings.

Example workflow (sanitise, build one message, safe headers):

// retrieve & sanitize
$first = trim(filter_input(INPUT_POST, 'firstname', FILTER_SANITIZE_STRING) ?? '');
$char  = str_replace(array("\r","\n"), '', trim($_POST['charname'] ?? ''));

// build a multi-line body cleanly
$body = <<<EOT
First name: $first
Character: $char
Class: {$_POST['class'] ?? ''}
Level: {$_POST['level'] ?? ''}
EOT

$body = wordwrap($body, 70);

// safe headers: use a domain sender and put user email in Reply-To
$hdrs = "From: no-reply@yourdomain.com\r\n";
if (!empty($_POST['email']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
  $hdrs .= "Reply-To: " . str_replace(array("\r","\n"), '', $_POST['email']) . "\r\n";
}

If a parse error like “unexpected T_VARIABLE” appears, run php -l filename.php and inspect the exact line and the one before it for missing semicolons, unmatched quotes, or an unterminated heredoc. For production, prefer a mail library (PHPMailer/SwiftMailer) to avoid header/encoding pitfalls. and addressed key points; ’s request for the full code is appropriate if syntax errors persist.

Recommended Answers

All 6 Replies

I think instead of:

$sent = mail($to, $subject, $firstname, $charname, $class, $level, $age, $timezone, $raidavail, $mmoexp, $charlink, $s2_q1, $s2_q2, $s2_q3, $s2_q4, $s2_q5, $s2_q6, $s2_q7, $s2_q8, $s3_q1, $s3_q2, $s3_q3, $s3_q4, $s3_q5, $s3_q6, $s3_q7, $headers) ;

You want

$sent = mail($to, $subject, $firstname . $charname . $class . $level .  $age. $timezone . $raidavail . $mmoexp . $charlink . $s2_q1 .  $s2_q2 . $s2_q3 . $s2_q4 . $s2_q5 . $s2_q6 .  $s2_q7 .  $s2_q8 .  $s3_q1 . $s3_q2 .  $s3_q3 . $s3_q4 .  $s3_q5 . $s3_q6 . $s3_q7, $headers) ;

Notice that between $firstname and $s3_q7 , I used the '.' operator (which concatenates the variables), rather than a comma.

This is because the prototype for the function mail looks like this (as you're attempting to use it):

mail($to, $subject, $message, $headers);

Note that this will send some REALLY ugly looking messages, unless your variables already have spaces and formatting in them (i doubt it :P)

Hey thank you, that got my post to actually POST, and send me an email. the problem is. I got this as my email:

TestTestGladiator2020CSTHigh

My form, I made an HTML page just so you can view it. hopefully you can tell me what I did wrong with it..

Hey thank you, that got my post to actually POST, and send me an email. the problem is. I got this as my email:

TestTestGladiator2020CSTHigh

My form, I made an HTML page just so you can view it. hopefully you can tell me what I did wrong with it..

The problem is that all your variables are being sent as one concatenated string. You need to put spaces/other formatting in between them, to create a better looking output. For example, the following will send 'First Name: and then everything else on a line by itself.

$sent = mail($to, $subject, $firstname . ': \n' .  $charname . '\n' . $class  . '\n' . $level  . '\n' . $age . '\n' . $timezone  . '\n' . $raidavail  . '\n' . $mmoexp  . '\n' . $charlink  . '\n' . $s2_q1  . '\n' . $s2_q2  . '\n' . $s2_q3  . '\n' . $s2_q4  . '\n' . $s2_q5  . '\n' . $s2_q6  . '\n' . $s2_q7  . '\n' . $s2_q8  . '\n' . $s3_q1  . '\n' . $s3_q2  . '\n' . $s3_q3  . '\n' . $s3_q4  . '\n' . $s3_q5  . '\n' . $s3_q6  . '\n' . $s3_q7, $headers) ;

By the way, you really should put the message into a variable, to make your code more readable (personal opinion)
so:

$message = $firstname . ': \n' .  $charname . '\n' . $class  . '\n' . $level  . '\n' . $age . '\n' . $timezone  . '\n' . $raidavail  . '\n' . $mmoexp  . '\n' . $charlink  . '\n' . $s2_q1  . '\n' . $s2_q2  . '\n' . $s2_q3  . '\n' . $s2_q4  . '\n' . $s2_q5  . '\n' . $s2_q6  . '\n' . $s2_q7  . '\n' . $s2_q8  . '\n' . $s3_q1  . '\n' . $s3_q2  . '\n' . $s3_q3  . '\n' . $s3_q4  . '\n' . $s3_q5  . '\n' . $s3_q6  . '\n' . $s3_q7;

$sent = mail($to, $subject, $message, $headers) ;

Ohhh, ok, thanks, I'll try that, and I'll try your suggestion first even.

Hmm.. I did what you said, I put in your bottom suggestion, and I got this error:
Parse error: syntax error, unexpected T_VARIABLE in /home/content/v/a/l/valthonic/html/submitform.php on line 57

Can you post the entire code so that we can tell what is wrong?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.