Sending an email via mail() - message is all jumbled up!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • daJunkCollector
    New Member
    • Jun 2007
    • 76

    Sending an email via mail() - message is all jumbled up!

    I created a form in flash. The user can fill out each field of the form and submit the information to the $sendTo email address just fine, however, I receive the email section, $message, all jumbled up! I need to put a line break between each section so that the email I receive is legible.

    I want each variable to appear on its own line.

    I assume there is an extremely easy fix for this, but I have been searching for hours. Your help is very much appreciated.




    [PHP]<?php
    $sendTo = "me@gmail.c om";
    $subject = "Subject of the email";

    $headers = "From: " . $_POST["contactVar "];
    $headers .= "<" . $_POST["emailVar"] . ">\r\n";
    $headers .= "Reply-To: " . $_POST["emailVar"] . "\r\n";
    $headers .= "Return-Path: " . $_POST["emailVar"];
    $message = $_POST["emailVar"];
    $message .= $_POST["agencyVar"];
    $message .= $_POST["address1Va r"];
    $message .= $_POST["address2Va r"];
    $message .= $_POST["cityVar"];
    $message .= $_POST["stateVar"];
    $message .= $_POST["zipcodeVar "];
    $message .= $_POST["phoneVar"];
    $message .= $_POST["faxVar"];
    $message .= $_POST["websiteVar "];
    $message .= $_POST["commentsVa r"];

    mail($sendTo, $subject, $message, $headers);

    ?>[/PHP]
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Changed thread title to better describe the problem (did you know that threads whose titles contain phrases such as 'please help' actually get FEWER responses?).

    Heya, daJunkCollector . Welcome to TSDN!

    You are putting newlines in your source code... but not your message body :(

    Try this instead:

    [code=php]
    <?php
    $sendTo = "me@gmail.c om";
    $subject = "Subject of the email";

    $headers = "From: $_POST[contactVar]";
    $headers .= "<$_POST[emailVar]>\r\n";
    $headers .= "Reply-To: $_POST[emailVar]\r\n";
    $headers .= "Return-Path: $_POST[emailVar]";

    $message = <<<EOT
    $_POST[emailVar]
    $_POST[agencyVar]
    $_POST[address1Var]
    $_POST[address2Var]
    $_POST[cityVar]
    $_POST[stateVar]
    $_POST[zipcodeVar]
    $_POST[phoneVar]
    $_POST[faxVar]
    $_POST[websiteVar]
    $_POST[commentsVar]
    EOT;

    mail($sendTo, $subject, $message, $headers);
    ?>
    [/code]

    Comment

    • digitalpbk
      New Member
      • Jun 2007
      • 4

      #3
      alternatively you can mail the entire in HTML format so you just need to add [HTML]<br/>[/HTML] after every line.

      [PHP]
      function sendHTMLMail($n ame,$email,$bod y,$title)
      {
      //recipient
      $to = $email ;

      // subject
      $subject = "";

      //HTML message TODO: Modify below
      $message = "
      <html>
      <head>
      <title>$title </title>
      </head>
      <body>
      $body
      </body>
      </html>
      ";

      // To send HTML mail, the Content-type header must be set
      $headers = "MIME-Version: 1.0" . "\r\n";
      $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";

      // Additional headers
      $headers .= "To: $name <$email>" . "\r\n";
      $headers .= "From: Nobody<no-reply@noreply.c om>" . "\r\n";

      // Mail it
      mail($to, $subject, $message, $headers);

      }
      [/PHP]

      Comment

      • daJunkCollector
        New Member
        • Jun 2007
        • 76

        #4
        Totally awesome. Both solutions worked great. I was in the right ballpark but just could not figure it out myself. Thank you very very much guys.

        Comment

        Working...