php email body

Posted on 2012-03-16
Medium Priority
Last Modified: 2012-04-03
Everything is working but when I tried to add dateTxt
as follow:

$finalmsg = $msgText + "<br>" + $dateTxt;

It no longer works....I basically just want to add parameter to $finalmsg so the email body will include datetxt.

Any php experts know how to fix it?



# some settings of POST vars
if (!isset($_POST['send']))  $send = ''; else $send = $_POST['send'];
if (!isset($_POST['toText'])) $toText = ''; else $toText = $_POST['toText'];
if (!isset($_POST['ccText'])) $ccText = ''; else $ccText = $_POST['ccText'];
if (!isset($_POST['subjectText'])) $subjectText = ''; else $subjectText = $_POST['subjectText'];
if (!isset($_POST['msgText'])) $msgText = ''; else $msgText = $_POST['msgText'];
if (!isset($_POST['dateTxt'])) $dateTxt = ''; else $dateTxt = $_POST['dateTxt'];
if (!isset($_POST['ccText'])) $ccTexth = ''; else $ccText = $_POST['ccText'];
if (!isset($_POST['bccText'])) $bccText = ''; else $bccText = $_POST['bccText'];
if (!isset($_POST['nameText'])) $nameText = ''; else $nameText = $_POST['nameText'];
if (!isset($_POST['fromText'])) $fromText = ''; else $fromText = $_POST['fromText'];

if ($send == "") {
    $title="Test Email Page";
else {
      if($fromText === "") die("No name!");
      $title="Test Email Page";
        $finalmsg = $msgText;
  $announce="Your Message has been Sent!";
      $header = "From: ".$fromText."\r\n";
//      $header .= "Cc: ".$ccText."\n";
      $header .= "Reply-To : ".$fromText."\r\n";
      $header .= "Return-Path : ".$fromText."\r\n";
      $header .= "X-Mailer: PHP\r\n";
      $header .= "MIME-Version: 1.0\r\n";
      $header .= "Content-Type: text/plain; charset=iso-8859-1\r\n";
//      ini_set(sendmail_from,$fromText);  
      mail($toText, $subjectText, $finalmsg, $header, '-f'.$fromText);
//      ini_restore(sendmail_from);
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN" dir="ltr">
<head profile="http://gmpg.org/xfn/11">
<title>911 Dentistry >> Schedule Appointment</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="imagetoolbar" content="no" />
<link rel="stylesheet" href="styles/layout.css" type="text/css" />
<script type="text/javascript">
function check()
var at=document.getElementById("fromText").value.indexOf("@");
var eml=document.getElementById("fromText").value;
var nam=document.getElementById("nameText").value;
var alerttxt="";
var submitOK="true";

if (eml.length < 5 || at == -1)
    alerttxt=alerttxt+"Please enter a valid e-mail address!\r\n";
    //return false;
if (nam.length < 3)
    alerttxt=alerttxt+"Please enter your name.\r\n";
    //return false;
if (submitOK=="false")
    return false;

// -->
<body id="top">
<div class="wrapper col1">
  <div id="topbar">
    <p>    <span class="TextInWhite">Tel: 310.552.1441</span> | <a title="s"  href="homepage.html"><span class="TextInWhite">s</span></a></p>
      <li><a href="testimonials.html" title="Clients Testimonials "><span class="TextInWhite">Client Testimonials</span></a></li>
      <li><a href="scheduleappointment.html"><span class="TextInWhite">Schedule Appointment</span></a></li>
      <li><a href="dentalinsurance.html"><span class="TextInWhite">Dental Insurance</span></a></li>
      <li class="last"><a href="paymentoptions.html"><span class="TextInWhite">Payment Options</span></a></li>
    <br class="clear" />
<div class="wrapper col2">
  <div id="header">
    <div id="topnav">
        <li class="last"><a href="contactus.html">Contact Us</a><span></span></li>
        <li><a href="faq.html">FAQs</a><span></span></li>
        <li><a href="specialoffers.html">Special Offers</a><span></span></li>
        <li><a href="products.html">products</a><span></span></li>
        <li><a href="homepage.html">Home</a><span></span></li>
    <div id="logo">
      <h1><a href="homepage.html">Beverly Hills</a></h1>
    <br class="clear" />
<div class="wrapper col3">
  <div id="breadcrumb">
      <li class="first"><a href="homepage.html">Home</a></li>
      <li class="current"><a href="scheduleappointment.html" title="Schedule Appointment">Schedule Appointment</a></li>
<div class="wrapper col4">
  <div id="container">
    <div id="content">
      <h1>Schedule Appointment</h1>
      To schedule an appointment and/or consultation with Dr,
      simply fill out the form below.<br />We will contact you shortly to confirm
      your requested day and time.


if ($send != "") {
         echo ("To: ".$toText."<br>\r\nSubject: ".$subjectText."<br>\r\n".$msgText."<br>\r\n".$header);

<p><b><font color="#000000" size="5">Test Email</font></b></p>
<font size="4" color="#000000">

<!--   <form method="POST" action="<?php echo($PHP_SELF)?>"> -->
<form method="POST" action="scheduleappointment.php" onsubmit="return check();">
    <table summary="Schedule Appointment">
            <th colspan="2">Please enter the following information</th>          
     <tr class="light"><td>Name:</td><td><input type="text" name="nameText" id="nameText"></td></tr>
     <tr class="dark"><td>Email:</td><td><input type="text" name="fromText" id="fromText"></td></tr>
     <tr class="light"><td>Reasons for your visit:</td><td><textarea rows="5" id="msgText" name="msgText" cols="20"></textarea></td></tr>
     <tr class="dark" valign="top">
           <td>When would you like to come in?</td>
           <td>Date:<input type="text" name="dateTxt" id="dateTxt"></td>
     <tr><td><br></td><td><input class="IndividualSubmit" type="submit" value="Send" name="send"></td></tr>
    <input type="hidden" name="state" value="1">
    <input type="hidden" name="subjectText" value="Web Mail">
Question by:Webboy2008
LVL 83

Expert Comment

ID: 37731450
You're using the wrong operator to concatenate your string.
Currently : +
Should be : .
Yes a << dot >>
$finalmsg = $msgText . "<br>" . $dateTxt;

Open in new window

LVL 84

Expert Comment

by:Dave Baldwin
ID: 37731505
What he said.  The '+' is used in javascript to concatenate strings.  The '.' is used in PHP.

Author Comment

ID: 37731765
oh ! Thank. that looks easy to me. I will try later tonight. I am asp developer so ... u know what i mean..
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 111

Expert Comment

by:Ray Paseur
ID: 37735277
As an ASP developer, you will pick up PHP very quickly.  This book is a light read and will give you a good foundation in the syntax and common data structures.

I would like to take a moment to hate on this statement a little bit ;-)
if (!isset($_POST['send']))  $send = ''; else $send = $_POST['send'];

In PHP the $_POST array is populated from the HTML form tags.  If the input tag in the form is of type=text, it will always be set.  It may be empty(), but it will be set.  (The same is not true of radio buttons and checkboxes - they are not set if they were not activated by the client.)  The effect of testing for the post elements with isset() is usually not what you want.  A more common way of handling external input like this is to use some kind of filter that will let you sanitize the external input.  Some functions worth learning about:

A commonly used construct for these repeated "if" statements is the ternary operator, documented here:

Best regards, ~Ray
LVL 84

Expert Comment

by:Dave Baldwin
ID: 37735312
He's using my PHP Email demo code which is years old now.  I just keep using

if (!isset($_POST['send']))  $send = ''; else $send = $_POST['send'];

because it does what I want and maybe more important, I don't have to think about it.  So you can hate if you want but it's in a Lot of web pages now.  Besides getting the $_POST info, it also makes sure that the variables are set.  More not having to think about it later.
LVL 111

Expert Comment

by:Ray Paseur
ID: 37735358
Hey Dave -- not dissing you!  I have a lot of what can only be called, charitably, "legacy code" in my libraries too.  There is nothing wrong with keeping stuff that works.  It's just that the if-else part of the assignment statements is not necessary if the form has been posted.  Certainly it's a lot smarter than extract($_POST) or using register_globals.

I tend to use a set of REGEX to sanitize my incoming form fields.  If I were refactoring I would probably change to use filter_var.  But there is no real need to refactor working code until it falls into the deprecated bucket like the ereg() collection.

best to all, ~Ray
LVL 84

Expert Comment

by:Dave Baldwin
ID: 37735427
I ran into some situation where I didn't assign a variable and it didn't show up in the POST and drove me nuts trying to find it.  On my 'real' email forms, there are a couple of preg-something routines that I use to scan all the inputs checking for known signs of spam and SQL-injection.  I put that in when a customer's email forms started getting spammed with huge pages of useless crap.  By now that also falls into the 'legacy code' area.  I just use it and I never look at it unless it screws up on me.  My 'real' code is several times longer than my 'demo' page.  I've also started using the free GEOIP from Maxmind to get some idea where people are coming from.
LVL 111

Expert Comment

by:Ray Paseur
ID: 37735470
Yeah, I love GEOIO that is similar to the MaxMind thing.  IIRC you get a thousand free calls to the API each day.  This page is built with the data retrieved from it.  I have a couple of the "usual suspects" that I block.
LVL 84

Expert Comment

by:Dave Baldwin
ID: 37735504
I like that, it's pretty cool.
LVL 111

Accepted Solution

Ray Paseur earned 2000 total points
ID: 37735521
Thanks!  This site gets a lot better as the baseball season goes on :-)

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question