I am trying to put spaces in my concatenation

I have this code to put the information from my contact page into a data base and also send an email to me telling me someone filled out the contact page. Here is my the code for my PHP page.

            $con = mysql_connect("localhost","myusername","xxxmypassword");
                if (!$con)
                 die('Could not connect: ' . mysql_error());
                mysql_select_db("database name", $con);
                $sql="INSERT INTO table name (id, first_name, last_name, address, city, state, zip, area, exchange, phone, email_info, contact, services, comments)
                    ('$_POST[id]','$_POST[first_name]','$_POST[last_name]','$_POST[address]','$_POST[city]','$_POST[state]','$_POST[zip]','$_POST[area]','$_POST[exchange]','$_POST[phone]','$_POST[email_info]','$_POST[contact]','$_POST[services]','$_POST[comments]' )";
                    if (!mysql_query($sql,$con))
                 die('Error: ' . mysql_error());
                    $mail = new PHPMailer();
                    $mail->SMTPAuth = true;
                    $mail->Host = "smtp.gmail.com";
                    $mail->SMTPSecure = "ssl";
                    $mail->Port = 465;
                    $mail->Username = "myusername@gmail.com";
                    $mail->Password = "mypassword@gmail.com";
                    $mail->AddAddress("to email");
                    $mail->From = "Joe.K.Doe@gmail.com";
                    $mail->FromName = $_POST['name'];
                    $mail->Subject = "John someone has filled out your contact page!";
                    $mail->Body =$_POST['comments'].'First Name: '. $_POST['first_name' ].'Last Name: '. $_POST['last_name'].'Address: '.$_POST['address'].'City: '.$_POST['city'].'State: '.$_POST['state'].'Zip: '.$_POST['zip'].'Area: '.$_POST['area'].'Exchange: '.$_POST['exchange'].'Phone: '.$_POST['phone'].'Email Info: '.$_POST['email_info'].'Contact: '.$_POST['contact'].'Services: '.$_POST['services']; 
                    if($mail->Send()) {
                       echo "Thank you for contacting Us! We will get back to you as soon as possible!";
  and this is what the email looks like

I am ready to get this finished it has been a great chance to learn. First Name: JohnLast Name: DoeAddress: 21 WAWA Ave.City: ChicagoState: ILZip: 564883Area: 689Exchange: 675Phone: 9878Email Info: John@gmail.comContact: emailServices: babbitt bearings
see how all the words like First Name: JohnLast Name: DoeAddress: is all crammed together and it is hard to tell what starts where and what end where. I tried
between the $POST but that did not work. All comments greatly appreciated. Codin

If you want to use
you need to put it in double quotes, like "

’ (single quotes) doesn’t work.


ScallioXTX thank you for the help.
I wrote the code out like this

$mail->Body =$_POST['comments']"\
".'First Name: '. $_POST['first_name' ]"\
".'Last Name: '. $_POST['last_name'];

and I got this error code.

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\\xampp\\htdocs\\sendmail3.php on line 40

Thank you for all help. Codin

You forgot two dots in the concatenation:

$mail->Body=$_POST['comments'][COLOR="Red"][B] . [/B][/COLOR]"\
" . 'First Name: ' . $_POST['first_name'][COLOR="Red"][B] . [/B][/COLOR]"\
" . 'Last Name: ' . $_POST['last_name'];

See the dots in bold red.
Also when I have to concatenate a bunch of strings like this I always put a space in front of the concatenation dot and one after (like I did above). It makes it much easier to see what’s going on and also makes it easy to spot if you missed one.
May be just my preference, but it might help you too :slight_smile:

Thank you very much the example you sent me works great. I truly appreciate it.