Jump to content

need help fixing errors?


Boxerman

Recommended Posts

#1 has been shown to you, we have no idea how you have your code setup so we can't tell you what to use for #2, and you were pointed in the right direction for #3.   We don't write code for you.  We help you fix your own code.  If you wish for someone to write it for you, post in the freelance section (read the stickies first).

Link to comment
Share on other sites

Ok thanks guys, would it be like this,

 

<?php
// The message
$message = "$location = $_SERVER["PHP_SELF"];";

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);

// Send
mail('caffinated@example.com', 'My Subject', $message);
?>

 

Link to comment
Share on other sites

Using the line:

$message = "$location = $_SERVER["PHP_SELF"];";

 

Would have caused an error anyway (the double quotes would have confused PHP). DarkWater's code just makes it work like we presume you want it to. If for whatever reason you have taken a dislike to DarkWater's code, use:

 

$message = 'location = '.$_SERVER["PHP_SELF"];

 

Link to comment
Share on other sites

<html>

<body>

 

<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
  {
  //send email
  $email = $_REQUEST['email'] ; 
  $subject = $_REQUEST['subject'] ;
  $message = $_REQUEST['message'] ;
  mail("someone@example.com", "Subject: $subject",
  $message, "From: $email" );
  echo "Thank you for using our mail form";
  }
else
//if "email" is not filled out, display the form
  {
  echo "<form method='post' action='mailform.php'>
  Email: <input name='email' type='text' /><br />
  Subject: <input name='subject' type='text' /><br />
  Message:<br />
  <textarea name='message' rows='15' cols='40'>
  </textarea><br />
  <input type='submit' />
  </form>";
  }
?>

</body>
</html>

 

would that be around the lines?

Link to comment
Share on other sites

Change the line

echo "<form method='post' action='mailform.php'>

to

echo "<form method='post' action='".$_SERVER['PHP_SELF']."'>

 

And then yeah, that should be about right mate. Change $_REQUEST to $_POST as well. It's just better practise seeing as you're only looking for the $_POST variable ($_REQUEST contains $_POST, $_GET and $_COOKIE).

Link to comment
Share on other sites

<input type="checkbox" name="check" />

 

When someone checks it, it's value will be on ($_POST['check'] == 'on'), if someone doesn't check it, $_POST['check'] doesn't exist (you can check if it exists using isset($_POST['check']).

Link to comment
Share on other sites

<input type="checkbox" name="check" />

 

Is the HTML for making a checkbox. Put this in your form.

 

To see if someone has checked it or not, in your form processing section, use:

 

if(isset($_POST['check']))
{
    // The checkbox has been checked. Do something here.
}

 

So altogether, your code may look something like this:

 

<?php
if (isset($_POST['email']))
//if "email" is filled out, send email
  {
  //send email
  $email = $_POST['email'] ; 
  $subject = $_POST['subject'] ;
  $message = $_POST['message'] ;
  if(isset($_POST['check']))
  {
    $message .= ' The user checked the checkbox.';
  }
  mail("someone@example.com", "Subject: $subject",
  $message, "From: $email" );
  echo "Thank you for using our mail form";
  }
else
//if "email" is not filled out, display the form
  {
  echo "<form method='post' action='".$_SERVER['PHP_SELF']."'>
  Email: <input name='email' type='text' /><br />
  Subject: <input name='subject' type='text' /><br />
  Message:<br />
  <textarea name='message' rows='15' cols='40'>
  </textarea><br />
  Checkbox: <input type="checkbox" name="check" /><br />
  <input type='submit' />
  </form>";
  }
?>

</body>
</html>

 

The bit inside the if statement uses .= to add a sentence to the end of $message.

Link to comment
Share on other sites

Again this is down to HTML (and CSS) not PHP. To apply a background color to an HTML element on a page with CSS do:

<style type="text/css">
/* CSS syntax

html_tag_name {
    attribute: value
}*/

/* REAL EXAMPLE */
form {
   background-color: #FFCC00;
}

The above CSS will give your form an orange background color.

 

There are many CSS tutorials onlines, have a look at the tutorials over at w3school.com

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.