Sending 'extra' information with emails

Soldato
Joined
30 Apr 2007
Posts
3,095
Location
Kent
Hi Guys,

I'm using this PHP form script

Code:
<?php 
$name =    $_POST ['name'];
$email =   $_POST ['email'];
$subject = $_POST ['subject'];
$message = $_POST ['message'];

$to = "<snip>";
$re = $subject;
$headers = 'From: '.$email.'' . "\r\n" . 
'Reply-To: '.$email.'' . "\r\n" . 
'X-Mailer: PHP/' . phpversion(); 

if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) { 
Echo "Fail Message";
} 
else {
mail ($to, $re, $message, $headers);
echo "Your email has been sent. Thank you for your email, we will deal with your email shortly.";
}
?>

I would like to send an extra field, i.e. a phone number inside of the email, is this possible?
 
Add an extra field to the form, get the POST data and then concatenate with a new line and message and then send that new variable as the message?
 
So, for arguments sake I would do something like this:

Code:
<?php
$phone = $_POST ['phone'];
$message = $_POST ['message'];

$combined="$message /n $phone";

?>

Of course, I would use the $combined variable in place of the current $message variable.

Is that what you're talking about?
 
Nearly :)

$combined = $message."/n".$phone;

That will send you an email with the content of the message, and then at the bottom of the message will be the user's phone number.

Also i recommend doing your cleaning/validation of user input before the concatenation. :)
 
Nearly :)

$combined = $message."/n".$phone;

That will send you an email with the content of the message, and then at the bottom of the message will be the user's phone number.

Also i recommend doing your cleaning/validation of user input before the concatenation. :)

Do you mean using another eregi statement?

You want \n rather than /n too.

You're right!
 
Back
Top Bottom