Link to home
Start Free TrialLog in
Avatar of Webboy2008
Webboy2008

asked on

php email body

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?

Thanks


<?php
error_reporting(E_ALL);
ini_set('display_errors','On');

# 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";
    $announce="---";
}
else {
      if($fromText === "") die("No name!");
  $toText="asdfasdfasdf@yahoo.com";
      $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";
    submitOK="false"
    //return false;
    }
if (nam.length < 3)
    {
    alerttxt=alerttxt+"Please enter your name.\r\n";
    submitOK="false"
    //return false;
    }
if (submitOK=="false")
    {
    alert(alerttxt);
    return false;
    }

}
// -->
</script>
</head>
<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>
    <ul>
      <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>
    </ul>
    <br class="clear" />
  </div>
</div>
<div class="wrapper col2">
  <div id="header">
    <div id="topnav">
      <ul>
        <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>
      </ul>
    </div>
    <div id="logo">
      <h1><a href="homepage.html">Beverly Hills</a></h1>
      <p></p>
    </div>
    <br class="clear" />
  </div>
</div>
<div class="wrapper col3">
  <div id="breadcrumb">
    <ul>
      <li class="first"><a href="homepage.html">Home</a></li>
      <li>&#187;</li>
      <li class="current"><a href="scheduleappointment.html" title="Schedule Appointment">Schedule Appointment</a></li>
    </ul>
  </div>
</div>
<div class="wrapper col4">
  <div id="container">
    <div id="content">
      <h1>Schedule Appointment</h1>
      <p>
      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.
      </p>


 

<?php
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">
    <thead>
          <tr>
            <th colspan="2">Please enter the following information</th>          
          </tr>
     </thead>
     <tbody>
     <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>
     <tr><td><br></td><td><input class="IndividualSubmit" type="submit" value="Send" name="send"></td></tr>
     </tbody>
     </table>
    <input type="hidden" name="state" value="1">
    <input type="hidden" name="subjectText" value="Web Mail">
  </form>
</body>
</html>
Avatar of leakim971
leakim971
Flag of Guadeloupe image

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

Open in new window

What he said.  The '+' is used in javascript to concatenate strings.  The '.' is used in PHP.
Avatar of Webboy2008
Webboy2008

ASKER

oh ! Thank. that looks easy to me. I will try later tonight. I am asp developer so ... u know what i mean..
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.
http://www.sitepoint.com/books/phpmysql4/

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:
http://php.net/manual/en/function.empty.php
http://php.net/manual/en/function.filter-var.php

A commonly used construct for these repeated "if" statements is the ternary operator, documented here:
http://php.net/manual/en/language.operators.comparison.php

Best regards, ~Ray
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.
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
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.
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.
http://www.landonbaseball.com/site_visitors.php
I like that, it's pretty cool.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial