PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
It is currently Sun Jul 05, 2020 9:31 am

All times are UTC - 5 hours

Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Tue Feb 05, 2013 5:44 pm 
Forum Newbie

Joined: Tue Feb 05, 2013 5:35 pm
Posts: 1
I can not for the life of me figure out how to send all the variables in the email message. Here is my code:

//client variables
$name = $_POST["name"];
$title = $_POST["title"];
$ftlt = $_POST["ftlt"];
$phone = $_POST["subject"];
$mobile = $_POST["mobile"];
$street = $_POST["street"];
$city = $_POST["city"];
$zip = $_POST["zip"];
$license = $_POST["license"];
$desired = $_POST["desired"];
$subject = $_POST["subject"];
$message = $_POST["message"];
$email = $_POST["email"];
$verif_box = $_POST["verif_box"];

$message = stripslashes($message);
$subject = stripslashes($subject);
$name = stripslashes($name);
$title = stripslashes($title);
$ftlt = stripslashes($mobile);
$phone = stripslashes($phone);
$mobile = stripslashes($mobile);
$street = stripslashes($state);
$city = stripslashes($city);
$zip = stripslashes($zip);
$license = stripslashes($license);
$desired = stripslashes($desired);

// validate verification code
if(md5($verif_box).'a4xn' == $_COOKIE['tntcon']){
// if pass send message
mail("", 'Online Form: '.$subject, $_SERVER['REMOTE_ADDR']."\n\n".$message, "email: $email");
// cookie deletion
} else if(isset($message) and $message!=""){
// if verif entry incorrect error message
header("Location: index.php?subject=$subject&from=$from&message=".urlencode($message)."&wrong_code=true");
} else {
echo "no variables received, this page cannot be accessed directly";

His issue is with this line of code. How do we add the client variables to achieve proper output in the sent message?

mail("", 'Online Form: '.$subject, $_SERVER['REMOTE_ADDR']."\n\n".$message, "email: $email");

Would I use the "\n\nname: ".$name. for each variable?

My php coding is minimal. Any help appreciated!

PostPosted: Tue Feb 05, 2013 6:44 pm 
Forum Contributor
User avatar

Joined: Wed Apr 14, 2010 4:45 pm
Posts: 375
Location: UK

You need to concatenate all the form values - as an example:

Syntax: [ Download ] [ Hide ]
$message .= 'Sender: ' . $name . PHP_EOL;

The important point to look at in this code is the .= operator, because what this does is append any new information to that already stored in the $message variable. The PHP_EOL code is used when you're outputting the email in plaintext format (rather than HTML) to create a compatible line break - if you *are* using HTML then you can either format the different sections of the message into their own paragraphs or just add line breaks (<br> for HTML 4.1).


Mecha Godzilla

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours

Who is online

Users browsing this forum: No registered users and 15 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group