Page 1 of 1

Trouble with my Mail Form / form mail

Posted: Wed Jan 30, 2008 4:31 am
by Gachet
Hi

I am trying to modify a php mail form. I have added in a new field called 'telephone' but now the text I type in the text box isn't displaying in the email that I receive.

Could someone have a look and see what I have done wrong please?

Thanks


mail.php:

Code: Select all

<?php
@extract($_POST);
$name = stripslashes($name);
$email = stripslashes($email);
$subject = stripslashes(Reflexology);
$telephone = stripslashes($telephone);
$text = stripslashes($text);
 
$text = $telephone;
$text = $text;
$text .= "\n\n IP Address: " . $_SERVER['REMOTE_ADDR'];
  if ($_SERVER['HTTP_X_FORWARDED_FOR']) 
  {
  $text .= " or Proxy Reports: " . $_SERVER['HTTP_X_FORWARDED_FOR'];
  }
$text .=  "\n\nUser Agent: " . stripslashes($_SERVER['HTTP_USER_AGENT']);
mail('X@gmail.com', $subject,$text,"From: $name <$email>");
header("location:mailsent.htm"); 
?>
The HTML form:

Code: Select all

<form action="mail.php" method="post">
        <div align="center">
          <div align="left"><span >Your name: </span></div>
          <div align="left">
            <input name="name" type="text" class="text-box"  size="47%" maxlength="50">
          </div>
          <div align="left"><span>Your e-mail address: </span></div>
          <div align="left">
            <input name="email" type="text" class="text-box"  size="47%" maxlength="50">
          </div>
          <div align="left"><span >Your telephone number: </span></div>
          <div align="left">
            <input name="telephone" type="text" class="text-box" size="47%" maxlength="50">
          </div>
          <div align="left"><span>Your message:</span></div>
          <div align="left">
            <textarea name="text" cols="35%" rows="6" class="text-box" id="text" ></textarea>
          </div>
          <div align="left">
            <input name="submit" type="submit" class="button"   onClick="return document.MM_returnValue" value="send">
            <input name="Reset" type="reset" class="button" value="reset">
 
</div>
        </div>
      </form>

Re: Trouble with my Mail Form / form mail

Posted: Wed Jan 30, 2008 4:59 am
by aceconcepts
Just from glancing at mail.php you probably want to surround your subject (Reflexology) with quotation marks so it should look like this:

Code: Select all

$subject = stripslashes("Reflexology");
Unless its a variable, in which case you would be missing the dollar sign.

Re: Trouble with my Mail Form / form mail

Posted: Wed Jan 30, 2008 5:16 am
by Gachet
Thanks.

The subject was working any ways but I have updated the file.

Any ideas why the message isn't displaying?

Re: Trouble with my Mail Form / form mail

Posted: Wed Jan 30, 2008 5:20 am
by aceconcepts
Take a look at lines 9 and 10

You end up setting the variable $text as $telephone.

Re: Trouble with my Mail Form / form mail

Posted: Wed Jan 30, 2008 6:03 am
by Gachet
Thanks.

I have changed it to this:

Code: Select all

<?php
@extract($_POST);
$name = stripslashes($name);
$email = stripslashes($email);
$subject = stripslashes("Reflexology");
$telephone = stripslashes($telephone);
$text = stripslashes($text);
 
 
$text = $text;
$text .= "\n\n IP Address: " . $_SERVER['REMOTE_ADDR'];
  if ($_SERVER['HTTP_X_FORWARDED_FOR']) 
  {
  $text .= " or Proxy Reports: " . $_SERVER['HTTP_X_FORWARDED_FOR'];
  }
$text .=  "\n\nUser Agent: " . stripslashes($_SERVER['HTTP_USER_AGENT']);
mail('x@gmail.com', $subject,$text,[b]$telephone[/b],"From: $name <$email>");
header("location:mailsent.htm"); 
?>
The telephone number and the text box text is being displayed in the email but now the 'from' field on the email is not being filled in with what it entered in the form.

Where can I put the '$telephone' for it to be displayed in the email without it affecting anything thats already there?

Thanks

Re: Trouble with my Mail Form / form mail

Posted: Wed Jan 30, 2008 6:16 am
by aceconcepts
Try setting the "From" parameter in the mail() function as a single variable

i.e.:

Code: Select all

 
$from=$name . "<" . $email . ">";
 
Do the above and then insert it into your mail() function like this:

Code: Select all

mail('x@gmail.com', $subject,$text,$telephone,"-f $from");

Re: Trouble with my Mail Form / form mail

Posted: Wed Jan 30, 2008 6:31 am
by Gachet
Right, it now looks like this:

Code: Select all

<?php
@extract($_POST);
$name = stripslashes($name);
$email = stripslashes($email);
$subject = stripslashes("Reflexology");
$telephone = stripslashes($telephone);
$text = stripslashes($text);
$from=$name . "<" . $email . ">";
 
 
$text = $text;
$text .= "\n\n IP Address: " . $_SERVER['REMOTE_ADDR'];
  if ($_SERVER['HTTP_X_FORWARDED_FOR']) 
  {
  $text .= " or Proxy Reports: " . $_SERVER['HTTP_X_FORWARDED_FOR'];
  }
$text .=  "\n\nUser Agent: " . stripslashes($_SERVER['HTTP_USER_AGENT']);
mail('x@gmail.com', $subject,$text,$telephone,"-f $from");
header("location:mailsent.htm"); 
?>
But its not showing the name of who it is from.

Thanks

Re: Trouble with my Mail Form / form mail

Posted: Wed Jan 30, 2008 6:47 am
by aceconcepts
Does it show the "from" email address?

Re: Trouble with my Mail Form / form mail

Posted: Wed Jan 30, 2008 7:55 am
by Gachet
Yes it does.

Re: Trouble with my Mail Form / form mail

Posted: Wed Jan 30, 2008 8:27 am
by aceconcepts
Ok, try amending the $from value to:

Code: Select all

$from="$name <$email>";

Re: Trouble with my Mail Form / form mail

Posted: Wed Jan 30, 2008 8:41 am
by Gachet
No joy.

Now its not showing the from email address either.

Re: Trouble with my Mail Form / form mail

Posted: Wed Jan 30, 2008 9:12 am
by aceconcepts
Ok,

Try it like this:

Code: Select all

$from=$name . "<" . $email . ">";
and take out the "-f" from the mail() function.

Re: Trouble with my Mail Form / form mail

Posted: Wed Jan 30, 2008 9:56 am
by Gachet
Now the from name or email aren't showing.

Code: Select all

<?php
@extract($_POST);
$name = stripslashes($name);
$email = stripslashes($email);
$subject = stripslashes("Reflexology");
$telephone = stripslashes($telephone);
$text = stripslashes($text);
$from=$name . "<" . $email . ">";
 
 
$text = $text;
$text .= "\n\n IP Address: " . $_SERVER['REMOTE_ADDR'];
  if ($_SERVER['HTTP_X_FORWARDED_FOR']) 
  {
  $text .= " or Proxy Reports: " . $_SERVER['HTTP_X_FORWARDED_FOR'];
  }
$text .=  "\n\nUser Agent: " . stripslashes($_SERVER['HTTP_USER_AGENT']);
mail('x@gmail.com', $subject,$text,$telephone,"-f $from");
header("location:mailsent.htm"); 
?>

Re: Trouble with my Mail Form / form mail

Posted: Wed Jan 30, 2008 10:27 am
by aceconcepts
To save you and me time and yespecially your testing effort take a look at this link: http://uk.php.net/manual/en/function.mail.php and in paerticular example 4.

It should be able to help you out - I'm not palming you off :D

If you want more help with the example then reply.

Re: Trouble with my Mail Form / form mail

Posted: Wed Jan 30, 2008 10:37 am
by RobertGonzalez
Untested...

Code: Select all

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  // instead of extracting and then applying strip slashes why not loop and apply at once?
  foreach ($_POST as $k => $v) {
    ${$k} = stripslashes($v);
  }
  $from = $email;
  $text .= "\n\n IP Address: " . $_SERVER['REMOTE_ADDR'];
  if ($_SERVER['HTTP_X_FORWARDED_FOR']) {
    $text .= " or Proxy Reports: " . $_SERVER['HTTP_X_FORWARDED_FOR'];
  }
  $text .=  "\n\nUser Agent: " . stripslashes($_SERVER['HTTP_USER_AGENT']);
  if (mail('joefylan@gmail.com', $subject, $text, "From: $from\r\n")) {
    header("Location: http://fulluriasperspec.com/mailsent.htm"); 
  } else {
    die('The mail message could not be sent.'); // This is for testing, not production use
 }
}
?>
On a side note, why not look into something like Swiftmailer?