PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Gachet
Forum Newbie
Posts: 8 Joined: Wed Jan 30, 2008 4:21 am
Post
by Gachet » Wed Jan 30, 2008 4:31 am
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>
aceconcepts
DevNet Resident
Posts: 1424 Joined: Mon Feb 06, 2006 11:26 am
Location: London
Post
by aceconcepts » Wed Jan 30, 2008 4:59 am
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.
Gachet
Forum Newbie
Posts: 8 Joined: Wed Jan 30, 2008 4:21 am
Post
by Gachet » Wed Jan 30, 2008 5:16 am
Thanks.
The subject was working any ways but I have updated the file.
Any ideas why the message isn't displaying?
aceconcepts
DevNet Resident
Posts: 1424 Joined: Mon Feb 06, 2006 11:26 am
Location: London
Post
by aceconcepts » Wed Jan 30, 2008 5:20 am
Take a look at lines 9 and 10
You end up setting the variable $text as $telephone.
Gachet
Forum Newbie
Posts: 8 Joined: Wed Jan 30, 2008 4:21 am
Post
by Gachet » Wed Jan 30, 2008 6:03 am
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
aceconcepts
DevNet Resident
Posts: 1424 Joined: Mon Feb 06, 2006 11:26 am
Location: London
Post
by aceconcepts » Wed Jan 30, 2008 6:16 am
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");
Gachet
Forum Newbie
Posts: 8 Joined: Wed Jan 30, 2008 4:21 am
Post
by Gachet » Wed Jan 30, 2008 6:31 am
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
aceconcepts
DevNet Resident
Posts: 1424 Joined: Mon Feb 06, 2006 11:26 am
Location: London
Post
by aceconcepts » Wed Jan 30, 2008 6:47 am
Does it show the "from" email address?
Gachet
Forum Newbie
Posts: 8 Joined: Wed Jan 30, 2008 4:21 am
Post
by Gachet » Wed Jan 30, 2008 7:55 am
Yes it does.
aceconcepts
DevNet Resident
Posts: 1424 Joined: Mon Feb 06, 2006 11:26 am
Location: London
Post
by aceconcepts » Wed Jan 30, 2008 8:27 am
Ok, try amending the $from value to:
Gachet
Forum Newbie
Posts: 8 Joined: Wed Jan 30, 2008 4:21 am
Post
by Gachet » Wed Jan 30, 2008 8:41 am
No joy.
Now its not showing the from email address either.
aceconcepts
DevNet Resident
Posts: 1424 Joined: Mon Feb 06, 2006 11:26 am
Location: London
Post
by aceconcepts » Wed Jan 30, 2008 9:12 am
Ok,
Try it like this:
and take out the "-f" from the mail() function.
Gachet
Forum Newbie
Posts: 8 Joined: Wed Jan 30, 2008 4:21 am
Post
by Gachet » Wed Jan 30, 2008 9:56 am
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");
?>
Last edited by
Gachet on Wed Jan 30, 2008 10:48 am, edited 1 time in total.
aceconcepts
DevNet Resident
Posts: 1424 Joined: Mon Feb 06, 2006 11:26 am
Location: London
Post
by aceconcepts » Wed Jan 30, 2008 10:27 am
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
If you want more help with the example then reply.
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Wed Jan 30, 2008 10:37 am
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 ?