1

Possible Duplicate:
PHP Pear - adding variables to $body message (resolved)

I have a jQuery page with a basic form and i stored each entered information into a specific variable which then uses Ajax but when I submit the form

It works but it sends only one variable in the message rather then multiple variables which I need..

The variables are correctly linked up because I can have the function having either one of those variables and it displays it but when I try send multiple it only shows one.

I apologize if its not clear enough its quite hard to explain, I thought using +'s would work but it did not.

<?php

$telephone = $_POST['telephone'];
$address = $_POST['address'];
$email = $_POST['email'];
$feedback = $_POST['feedback'];

mail($email,"hello" ,$feedback+$address+$telephone);

?>
Community
  • 1
  • 1
Hashey100
  • 994
  • 5
  • 22
  • 47

3 Answers3

3

The plus + operator is for numeric values.

$feedback+$address+$telephone 

So your addition will lead to a 0.

Use the string concatenation operator . or just a string with variables in it:

"  $feedback $address $telephone  "

See also:

Community
  • 1
  • 1
mario
  • 144,265
  • 20
  • 237
  • 291
3

its like

 mail(to,subject,message,headers,parameters) 

try

$message="$feedback.$address.$telephone";
mail($email,"hello" ,$message);
NullPoiиteя
  • 56,591
  • 22
  • 125
  • 143
2

Your code looks fine. You might have the Java Style of string concatenation (check http://php.net/manual/en/language.operators.string.php) Try to put all the string variables in one $message string and you are good to go.

<?php

$telephone = $_POST['telephone'];
$address = $_POST['address'];
$email = $_POST['email'];
$feedback = $_POST['feedback'];
$message="$feedback.$address.$telephone";
mail($email,"hello" ,$message);

?>

Since the mail function in php returns boolean, you can also do some check:

<?php
if (!mail($email,"hello" ,$message)){
//LOG ERROR 
//OR output
echo "Could not send mail, try checking php logs or enable logs via ini_set('display_errors',1)"
}
Al-Punk
  • 3,531
  • 6
  • 38
  • 56