Info from form shows in headers but not in body of email

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sadieslc
    New Member
    • Dec 2007
    • 2

    Info from form shows in headers but not in body of email

    I'm working on a PHP script, and the info from the form shows up in the headers of the email that I receive, but it doesn't show up in the body of the email. Can you please help me figure out what I'm doing wrong?

    Here is the script:
    [code=php]
    <? function send_mail($emai laddress, $fromaddress, $emailsubject, $body)
    {
    $eol="\r\n";
    $mime_boundary= md5(time());

    # Common Headers
    $headers .= 'From: Sending Love<'.$fromadd ress.'>'.$eol;
    $headers .= 'Reply-To: Sending Love<'.$fromadd ress.'>'.$eol;
    $headers .= 'Return-Path: Sending Love<'.$fromadd ress.'>'.$eol; // these two to set reply address
    $headers .= "Message-ID: <".$now." TheSystem[color=black]@[/color]".$_SERVER['SERVER_NAME'].">".$eol;
    $headers .= "X-Mailer: PHP v".phpversion() .$eol; // These two to help avoid spam-filters

    # Boundry for marking the split & Multitype Headers
    $headers .= 'MIME-Version: 1.0'.$eol;
    $headers .= "Content-Type: multipart/related; boundary=\"".$m ime_boundary."\ "".$eol;

    $msg = "";

    # Setup for text OR html
    $msg .= "Content-Type: text".$eol;

    # Text Version
    $msg .= "--".$mime_boundar y.$eol;
    $msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
    $msg .= "Content-Transfer-Encoding: 8bit".$eol;
    $msg .= strip_tags(str_ replace("<br>", "\n", $body)).$eol.$e ol;

    # HTML Version
    $msg .= "--".$mime_boundar y.$eol;
    $msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
    $msg .= "Content-Transfer-Encoding: 8bit".$eol;
    $msg .= $body.$eol.$eol ;

    # Finished
    $msg .= "--".$mime_boundar y."--".$eol.$eol ; // finish with two eol's for better security. see Injection.

    # SEND THE EMAIL
    ini_set(sendmai l_from,$fromadd ress); // the INI lines are to force the From Address to be used !
    mail($emailaddr ess, $emailsubject, $msg, $headers);
    ini_restore(sen dmail_from);
    #echo "mail send";
    }


    # To Email Address
    $emailaddress=" denise@REMOVED. net";

    # From Email Address
    $fromaddress = "orders@REMOVED .ca";

    # Message Subject
    $emailsubject=" Web Customer Submission";


    #----------------------------------------------------------------
    # Message Body
    $body = $body."This is a request for service from a customer <br>";
    $body = $body."<b>Custo mer Name: </b>".$_REQUEST['cust_name']."<br>";
    $body = $body."<b>Addre ss: </b>".$_REQUEST['cust_address']."<br>";
    $body = $body."<b>City: </b>".$_REQUEST['cust_city']."<br>";
    $body = $body."<b>Provi nce/State: </b>".$_REQUEST['cust_provstate ']."<br>";
    $body = $body."<b>Zip: </b>".$_REQUEST['cust_postzip']."<br>";
    $body = $body."<b>Count ry: </b>".$_REQUEST['cust_country']."<br>";
    $body = $body."<b>E-Mail: </b>".$_REQUEST['cust_email']."<br>";
    $body = $body."<b>Custo mer is Intersted in: </b>".$_REQUEST['cust_interest']."<br>";
    $body = $body."<b>Other Specification: </b>".$_REQUEST['cust_interest_ other']."<br>";
    $body = $body."<b>Desig n Selection: </b>".$_REQUEST['design_select']."<br>";
    $body = $body."<b>Color Preferences: </b>".$_REQUEST['color_pref']."<br>";
    $body = $body."<b>Custo mer Pertinent Info: </b>".$_REQUEST['cust_pertinfo']."<br>";
    $body = $body."<b>Anyth ing else the customer would like to see: </b>".$_REQUEST['cust_ideas']."<br>";
    $body = $body."<b>Thing s the customer doesn't want on their card: </b>".$_REQUEST['Cust_dont_want ']."<br>";
    $body = $body."<b>Card Size: </b>".$_REQUEST['card_size']."<br>";
    $body = $body."<b>Card Finish: </b>".$_REQUEST['card_finish']."<br>";
    $body = $body."<b>Quant ity: </b>".$_REQUEST['quantity']."<br>";
    $body = $body."<b>Can you use the finished product as a design example? : </b>".$_REQUEST['cust_permissio n']."<br>";
    $body = $body."<b>How did you find us?: </b>".$_REQUEST['found_us']."<br>";

    #Add all other parts here
    #----------------------------------------------------------------

    send_mail($emai laddress, $fromaddress, $emailsubject, $body);
    ?>
    [/code]
    TIA for your Help!
    Last edited by ak1dnar; Dec 22 '07, 06:42 AM. Reason: Email Addresses REMOVED and Fixed Code tags
  • Ranjan kumar Barik
    New Member
    • Aug 2007
    • 95

    #2
    Originally posted by sadieslc
    I'm working on a PHP script, and the info from the form shows up in the headers of the email that I receive, but it doesn't show up in the body of the email. Can you please help me figure out what I'm doing wrong?

    Here is the script:
    <? function send_mail($emai laddress, $fromaddress, $emailsubject, $body)
    {
    $eol="\r\n";
    $mime_boundary= md5(time());

    # Common Headers------------------headers not declared-------------
    $headers .= 'From: Sending Love<'.$fromadd ress.'>'.$eol;
    $headers .= 'Reply-To: Sending Love<'.$fromadd ress.'>'.$eol;
    $headers .= 'Return-Path: Sending Love<'.$fromadd ress.'>'.$eol; // these two to set reply address
    $headers .= "Message-ID: <".$now." TheSystem@".$_S ERVER['SERVER_NAME'].">".$eol;
    $headers .= "X-Mailer: PHP v".phpversion() .$eol; // These two to help avoid spam-filters

    # Boundry for marking the split & Multitype Headers
    $headers .= 'MIME-Version: 1.0'.$eol;
    $headers .= "Content-Type: multipart/related; boundary=\"".$m ime_boundary."\ "".$eol;

    $msg = "";

    # Setup for text OR html
    $msg .= "Content-Type: text".$eol;

    # Text Version
    $msg .= "--".$mime_boundar y.$eol;
    $msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
    $msg .= "Content-Transfer-Encoding: 8bit".$eol;
    $msg .= strip_tags(str_ replace("<br>", "\n", $body)).$eol.$e ol;

    # HTML Version
    $msg .= "--".$mime_boundar y.$eol;
    $msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
    $msg .= "Content-Transfer-Encoding: 8bit".$eol;
    $msg .= $body.$eol.$eol ;

    # Finished
    $msg .= "--".$mime_boundar y."--".$eol.$eol ; // finish with two eol's for better security. see Injection.

    # SEND THE EMAIL
    ini_set(sendmai l_from,$fromadd ress); // the INI lines are to force the From Address to be used !
    mail($emailaddr ess, $emailsubject, $msg, $headers);
    ini_restore(sen dmail_from);
    #echo "mail send";
    }


    # To Email Address
    $emailaddress=" denise@REMOVED. net";

    # From Email Address
    $fromaddress = "orders@REMOVED .ca";

    # Message Subject
    $emailsubject=" Web Customer Submission";


    #----------------------------------------------------------------
    # Message Body-----------------------body not declared----------------------
    $body = $body."This is a request for service from a customer <br>";
    $body = $body."<b>Custo mer Name: </b>".$_REQUEST['cust_name']."<br>";
    $body = $body."<b>Addre ss: </b>".$_REQUEST['cust_address']."<br>";
    $body = $body."<b>City: </b>".$_REQUEST['cust_city']."<br>";
    $body = $body."<b>Provi nce/State: </b>".$_REQUEST['cust_provstate ']."<br>";
    $body = $body."<b>Zip: </b>".$_REQUEST['cust_postzip']."<br>";
    $body = $body."<b>Count ry: </b>".$_REQUEST['cust_country']."<br>";
    $body = $body."<b>E-Mail: </b>".$_REQUEST['cust_email']."<br>";
    $body = $body."<b>Custo mer is Intersted in: </b>".$_REQUEST['cust_interest']."<br>";
    $body = $body."<b>Other Specification: </b>".$_REQUEST['cust_interest_ other']."<br>";
    $body = $body."<b>Desig n Selection: </b>".$_REQUEST['design_select']."<br>";
    $body = $body."<b>Color Preferences: </b>".$_REQUEST['color_pref']."<br>";
    $body = $body."<b>Custo mer Pertinent Info: </b>".$_REQUEST['cust_pertinfo']."<br>";
    $body = $body."<b>Anyth ing else the customer would like to see: </b>".$_REQUEST['cust_ideas']."<br>";
    $body = $body."<b>Thing s the customer doesn't want on their card: </b>".$_REQUEST['Cust_dont_want ']."<br>";
    $body = $body."<b>Card Size: </b>".$_REQUEST['card_size']."<br>";
    $body = $body."<b>Card Finish: </b>".$_REQUEST['card_finish']."<br>";
    $body = $body."<b>Quant ity: </b>".$_REQUEST['quantity']."<br>";
    $body = $body."<b>Can you use the finished product as a design example? : </b>".$_REQUEST['cust_permissio n']."<br>";
    $body = $body."<b>How did you find us?: </b>".$_REQUEST['found_us']."<br>";

    #Add all other parts here
    #----------------------------------------------------------------

    send_mail($emai laddress, $fromaddress, $emailsubject, $body);
    ?>

    TIA for your Help!
    Hi,
    The error is occurring here;
    [CODE=php]# Text Version
    $msg .= "--".$mime_boundar y.$eol;
    $msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
    $msg .= "Content-Transfer-Encoding: 8bit".$eol;
    $msg .= strip_tags(str_ replace("<br>", "\n", $body)).$eol.$e ol;

    # HTML Version
    $msg .= "--".$mime_boundar y.$eol;
    $msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
    $msg .= "Content-Transfer-Encoding: 8bit".$eol;
    $msg .= $body.$eol.$eol ;
    [/CODE]

    The problem is, I think, you are making the same body into text version and again making it to html version. Use of html body for html versioning and plain body for text versioning will do a fever.

    Two more errors in the coding.
    Just check it in your original post, I have marked those.
    Last edited by Ranjan kumar Barik; Dec 21 '07, 08:43 AM. Reason: Minimal correction

    Comment

    • sadieslc
      New Member
      • Dec 2007
      • 2

      #3
      Originally posted by Ranjan kumar Barik
      Hi,
      The error is occurring here;
      [CODE=php]# Text Version
      $msg .= "--".$mime_boundar y.$eol;
      $msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
      $msg .= "Content-Transfer-Encoding: 8bit".$eol;
      $msg .= strip_tags(str_ replace("<br>", "\n", $body)).$eol.$e ol;

      # HTML Version
      $msg .= "--".$mime_boundar y.$eol;
      $msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
      $msg .= "Content-Transfer-Encoding: 8bit".$eol;
      $msg .= $body.$eol.$eol ;
      [/CODE]

      The problem is, I think, you are making the same body into text version and again making it to html version. Use of html body for html versioning and plain body for text versioning will do a fever.

      Two more errors in the coding.
      Just check it in your original post, I have marked those.
      Ranjan,

      Should I take out one or the other of the versions? Also, how do I declare the body and the headers?

      Thanks,

      Denise

      Comment

      • Ranjan kumar Barik
        New Member
        • Aug 2007
        • 95

        #4
        Originally posted by sadieslc
        Ranjan,

        Should I take out one or the other of the versions? Also, how do I declare the body and the headers?

        Thanks,

        Denise
        By removing the Html version, the mail function works well but,
        you don't have to take out any one. You can declare two mail bodies like $text_body and $html_body and just pass two of them as parameters and make changes like this;
        [CODE=php]
        function send_mail($emai laddress, $fromaddress, $emailsubject, $text_body = "", $html_body ="")//Just To make them optional.
        {
        # Text Version
        $text_msg = "";
        $text_msg .= "--".$mime_boundar y.$eol;
        $text_msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
        $text_msg .= "Content-Transfer-Encoding: 8bit".$eol;
        $text_msg .= strip_tags(str_ replace("<br>", "\n", $body)).$eol.$e ol;
        $text_msg .= $text_body.$eol .$eol;

        # HTML Version
        $html_msg = "";
        $html_msg .= "--".$mime_boundar y.$eol;
        $html_msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
        $html_msg .= "Content-Transfer-Encoding: 8bit".$eol;
        $html_msg .= $html_body.$eol .$eol;
        [/CODE]
        When calling the function you can pass any one "text" or "html", because they are optional. If you don't pass any of the two then a blank message will be sent.

        I think it will work, just try.

        Merry Christ mass!
        :)

        Comment

        • ak1dnar
          Recognized Expert Top Contributor
          • Jan 2007
          • 1584

          #5
          Please do not post any email address with the code snippets. Thanks.

          Comment

          Working...