Jump to content

php form error


Boxerman

Recommended Posts

Hi guys!

 

i need help with this script,

 

this is the code:

 

<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
  {
  //send email
  $email = $_REQUEST['email'] ; 
  $subject = "Job Application" ;
  $firstname = $_REQUEST['firstname'] ;
  $lastname = $_REQUEST['lastname'] ;
  $age = $_REQUEST['age'] ;
  $reason = $_REQUEST['reason'] ;
  $timezone = $_REQUEST['timezone'] ;
  $times = $_REQUEST['times'] ;
  mail( "[email protected]", "Subject: $subject",
  $firstname, $lastname, $age, $reason, $timezone, $times, "From: $email" );
  echo "Thank you for applying!, please allow upto 24 hours for reply!";
  }
else
//if "email" is not filled out, display the form
  {
  echo "<form method='post' action='djapp.php'>
  First Name: <input name='firstname' type='text' /><br />
  Last Name: <input name='lastname' type='text' /><br />
  Email: <input name='email' type='text' /><br />
  Age: <input name='age' type='text' /><br />
  Time Zone: <input name='timezone' type='text' /><br />
  Times Can DJ: <input name='times' type='text' /><br />
  Reason for applying:<br />
  <textarea name='message' rows='10' cols='40' />

  </textarea><br />
  <input type='submit' />
  </form>";
  }
?>

 

 

 

when sending i get this :(

 

Warning: mail() expects at most 5 parameters, 9 given in /home/nonstopr/public_html/djapp.php on line 245

 

line 245 is in th e script above but to help the line is

 

  $firstname, $lastname, $age, $reason, $timezone, $times, "From: $email" );

 

thanks guys!

Link to comment
https://forums.phpfreaks.com/topic/119458-php-form-error/
Share on other sites

mail( "[email protected]", "Subject: $subject",  $firstname, $lastname, $age, $reason, $timezone, $times, "From: $email" );

 

I think you're using the mail() function not correctly.

 

PHP.NET

<?php

$to      = '[email protected]';

$subject = 'the subject';

$message = 'hello';

$headers = 'From: [email protected]' . "\r\n" .

    'Reply-To: [email protected]' . "\r\n" .

    'X-Mailer: PHP/' . phpversion();

 

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

?>

JaZz

Link to comment
https://forums.phpfreaks.com/topic/119458-php-form-error/#findComment-615367
Share on other sites

ok im confused, do i need to declare $message  then add the $firstname $lastname etc?

 

Like:

 

<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
  {
  //send email
  $email = $_REQUEST['email'] ; 
  $subject = "Job Application" ;
  $firstname = $_REQUEST['firstname'] ;
  $lastname = $_REQUEST['lastname'] ;
  $age = $_REQUEST['age'] ;
  $reason = $_REQUEST['reason'] ;
  $timezone = $_REQUEST['timezone'] ;
  $times = $_REQUEST['times'] ;


$to      = $email;
$subject = $subject;

$message = $firstname."\n";
$message .= $lastname."\n";
$message .= $reason."\n";
$message .= $timezone."\n";
$message .= $times."\n";

$headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

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


  echo "Thank you for applying!, please allow upto 24 hours for reply!";
  }
else
//if "email" is not filled out, display the form
  {
  echo "<form method='post' action='djapp.php'>
  First Name: <input name='firstname' type='text' /><br />
  Last Name: <input name='lastname' type='text' /><br />
  Email: <input name='email' type='text' /><br />
  Age: <input name='age' type='text' /><br />
  Time Zone: <input name='timezone' type='text' /><br />
  Times Can DJ: <input name='times' type='text' /><br />
  Reason for applying:<br />
  <textarea name='message' rows='10' cols='40' />

  </textarea><br />
  <input type='submit' />
  </form>";
  }

?>

 

JaZz

Link to comment
https://forums.phpfreaks.com/topic/119458-php-form-error/#findComment-615382
Share on other sites

Ok that emails me but doesnt show all of the fields?

 

 

<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
  {
  //send email
  $email = $_REQUEST['email'] ; 
  $subject = "Job Application" ;
  $firstname = $_REQUEST['firstname'] ;
  $lastname = $_REQUEST['lastname'] ;
  $email = $_REQUEST['email'] ;
  $age = $_REQUEST['age'] ;
  $reason = $_REQUEST['reason'] ;
  $timezone = $_REQUEST['timezone'] ;
  $times = $_REQUEST['times'] ;


$to      = "[email protected]";
$subject = $subject;

$message = $firstname."\n";
$message .= $lastname."\n";
$message .= $email."\n";
$message .= $reason."\n";
$message .= $timezone."\n";
$message .= $times."\n";

$headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

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


  echo "Thank you for applying!, please allow upto 24 hours for reply!";
  }
else
//if "email" is not filled out, display the form
  {
  echo "<form method='post' action='djapp.php'>
  First Name: <input name='firstname' type='text' /><br />
  Last Name: <input name='lastname' type='text' /><br />
  Email: <input name='email' type='text' /><br />
  Age: <input name='age' type='text' /><br />
  Time Zone: <input name='timezone' type='text' /><br />
  Times Can DJ: <input name='times' type='text' /><br />
  Reason for applying:<br />
  <textarea name='message' rows='10' cols='40' />

  </textarea><br />
  <input type='submit' />
  </form>";
  }

?>

Link to comment
https://forums.phpfreaks.com/topic/119458-php-form-error/#findComment-615386
Share on other sites

<?php
if ($_POST['submit']==true)
//if "email" is filled out, send email
  {
  //send email
  $email = $_POST['email'] ; 
  $subject = "Job Application" ;
  $firstname = $_POST['firstname'] ;
  $lastname = $_POST['lastname'] ;
  $email = $_POST['email'] ;
  $age = $_POST['age'] ;
  $reason = $_POST['reason'] ;
  $timezone = $_POST['timezone'] ;
  $times = $_POST['times'] ;


$to      = "[email protected]";
$subject = $subject;



$message .="\n";
$message .= $firstname."\n";
$message .= $lastname."\n";
$message .= $email."\n";
$message .= $reason."\n";
$message .= $timezone."\n";
$message .= $times."\n";

$headers ='From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

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


  echo "Thank you for applying!, please allow upto 24 hours for reply!";
  }
else
//if "email" is not filled out, display the form
  {
  echo "<form method='post' action=''djapp.php'>
  First Name: <input name='firstname' type='text' /><br />
  Last Name: <input name='lastname' type='text' /><br />
  Email: <input name='email' type='text' /><br />
  Age: <input name='age' type='text' /><br />
  Time Zone: <input name='timezone' type='text' /><br />
  Times Can DJ: <input name='times' type='text' /><br />
  Reason for applying:<br />
  <textarea name='message' rows='10' cols='40' />

  </textarea><br />
  <input type='hidden' name='submit' value='true' />
  <input type='submit' value='Submit' />
  </form>";
  }

?>

 

 

I've tested it on my server and it works fine. HERE

You needed to have a form (hidden value) that let the form know when to start sending...

Link to comment
https://forums.phpfreaks.com/topic/119458-php-form-error/#findComment-615419
Share on other sites

sure!

 

$message .= "Age: $age\n";

or keep the next line inticator separate to have a cleaner code:

$message .= "\n";

 

\n is equivalent to br (just so you know)

 

 

Happy Coding! ;)

 

 

LE: I'd really advise to take a look at the script i attached in the earlyer post... it will explane allot ;)

 

Link to comment
https://forums.phpfreaks.com/topic/119458-php-form-error/#findComment-615691
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.