Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

Concatenating variables in $msg for php email

Greetings,

I know how to basically set up the format for $msg such as:

$msg = "First Order: $tops_1\n" .
             "Name: $name\n" .
             
... etc.  What I need to know is how to concatenate variables on one line if need be.  

I would also like to know is how much freedom there is to format the $msg output in other ways and the formating/syntax to do that.  I know that  \n creates a line break and I think \t creates a tab space but I'm fuzzy on everything else.  I hope this is clear but if not, let me know what more information you need.      
0
max7
Asked:
max7
  • 5
  • 2
  • 2
  • +1
1 Solution
 
Michael701Commented:
like this?

$msg = "First Order: $tops_1\n" .
             "Name: $first_name $last_name\n" .
0
 
max7Author Commented:
but doesn't that just break into a separate line?  

I want to create a continuous string of information with the variables i.e. concatenate them into one long sentence.  I know how to do this otherwise in PHP but not sure how to do it within the mail() using $msg.
0
 
bored321Commented:
I'm not sure what you mean, like this?

$msg = "First Order: $tops_1 Name: $name";   ect..
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
max7Author Commented:
here's an example using the $_POST variable.  first_name and last_name are form field names from separate text inputs:

$name = $_POST['first_name']. ' ' .$_POST['last_name'];

By writing the POST variable in this manner, both first and last name are posted together i.e. they have been concatenated.  Does that make sense?
0
 
bored321Commented:
I understand the term concatenated, just not what you want.

like this?

$msg = $tops_1.$name;
0
 
max7Author Commented:
>>>like this?

$msg = $tops_1.$name;

I'm not sure what "like this?" means ... are you asking me if this is the correct way to concatenate a $msg string?  I'm asking the question because I don't know.  Please clarify what you are asking.
0
 
Michael701Commented:
Well the . (dot) is used to concatenate strings in PHP.

That being said there are a number of ways to arrive at the same outcome.

$a = "Hello ";
$b = "World!";

$c = $a.$b;
echo $c;
// Hello World!

$d = $a.$b. " this is Michael."
echo $d;
// Hello World! this is Michael.";

//PHP will also evaluate variables when inside double quoted strings. Note: NOT single quoted strings.

$e = "Michael said $a $b";
echo $e;
// Michael said Hello World!

0
 
dkaislaCommented:
remove the \n to display the msg in one line
0
 
max7Author Commented:
>>>remove the \n to display the msg in one line

Based on that advice, should the syntax for the strings below work?

$msg = "Order One - Top: $tops_1, Bottom: $bottoms_1, Color: $color_1, Size: $size_1, Quantity: $quantity_1\n" .
                "Order two - Top: $tops_2, Bottom: $bottoms_2, Color: $color_2, Size: $size_2, Quantity: $quantity_2\n" .

0
 
dkaislaCommented:
yup, it should display one order per line :)
0
 
max7Author Commented:
You're right: it worked.  Thanks!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 5
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now