php email body

Posted on 2012-03-16
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" "">
<html xmlns="" xml:lang="EN" lang="EN" dir="ltr">
<head profile="">
<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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 82

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 83

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..
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

LVL 110

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 83

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 110

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 83

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 110

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 83

Expert Comment

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

Accepted Solution

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

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This article discusses how to implement server side field validation and display customized error messages to the client.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

635 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