Jump to content

Dealing with form data


graham23s

Recommended Posts

Hi Guys,

 

i have made a basic form (input your subject,message and send)

 

when doing tests the data is coming back with no line breaks and \r\n when i put the nl2br's in.

 

can anyone tell me the correct way to deal with the data so when it comes into your e-mail inbox it looks properly formatted.

 

thanks guys

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/139303-dealing-with-form-data/
Share on other sites

Hi Mate,

 

Sorry for the late reply this is the code in a switch:

 

<?php
  case "mass-email":
  
    // How many emails
    $q_num = "SELECT * FROM `fcp_customers`";
    $r_num = mysql_query($q_num);
    $n_num = mysql_num_rows($r_num);
  
    print("<form action=\"admin.php?page=mass-email\" method=\"POST\" onSubmit=\"return email_check()\" name=\"email_form\" >");
  
    // Mass e-mails form
    print("<table width='80%' border='0' cellpadding='5' cellspacing='1' class=\"tbl_login\"/>\n");
    print("<tr>\n");
    print("<td class=\"c3\" align=\"left\" colspan='2'><b>Mass / Individually E-Mail Customers</b></td>\n");
    print("</tr>\n"); 
    print("<tr class=\"c5\">\n");
    print("<td align=\"left\"><img src=\"images/pixel.gif\" width=\"1\" height=\"1\"></td><td align=\"left\"><img src=\"images/pixel.gif\" width=\"1\" height=\"1\"></td>\n");
    print("</tr>\n");
    print("<tr class=\"c1\">\n");
    print("<td class='font_for_forms' align='left'>E-Mail:</td><td class='font_for_forms' align='left'><select name=\"cus_emails\"><option value=\"0\">--> MASS EMAIL ALL CUSTOMERS! - ($n_num) <--</option>");
    
    $q_emails = "SELECT * FROM `fcp_customers`";
    $r_emails = mysql_query($q_emails);
    
    // Loop
    while ($a_emails = mysql_fetch_array($r_emails))
    {
     // Customers email
     $ID     = $a_emails['id']; 
     $emails = $a_emails['email'];
     
     // Print
     print("<option value=\"$emails\">[$ID] - $emails</option>");
    }
    
    print("</select></td>\n");
    print("</tr>\n"); 
    print("<tr>\n");
    print("<td class=\"font_for_forms\" align='left'>E-Mail Subject:</td><td class='font_for_forms' align='left'><input type=\"text\" name=\"cus_subject\" size=\"70\"></td>");
    print("</tr>\n"); 
    print("<tr class=\"c1\">\n");
    print("<td class=\"font_for_forms\" align='left' valign=\"top\">E-Mail Message:</td><td class='font_for_forms' align='left'><textarea name=\"cus_message\" rows=\"20\" cols=\"70\"></textarea></td>");
    print("</tr>\n"); 
    print("<tr>\n");
    print("<td colspan='2' class='font_for_forms' align='right'><input type='submit' name='submit_emails' value='Send!'></td>\n");
    print("</tr>\n");    
    print("</table>");
    
    print("</form>");
    
    // Deal with the submission
    if (isset($_POST['submit_emails']))
    {
      // Post vars
      $emailVal = $_POST['cus_emails'];
      $emailSub = escape_data($_POST['cus_subject'], 1); 
      $emailMsg = escape_data($_POST['cus_message'], 1);; 
      
        // SUB IF
        if ($emailVal == "0")
        {
         // EMAIL ALL
         // SELECT ALL EMAILS
         $qE = "SELECT * FROM `fcp_customers`";
         $rQ = mysql_query($qE) or die (mysql_error());
         
         // LOOP
         while ($aE = mysql_fetch_array($rQ))
         {
         
         $emails      = $aE['email'];
         $emailsArray = array($emails); 

              // SEND EMAILS
              foreach($emailsArray as $EMAIL)
              {
                  $to = "$EMAIL";
                  $subject = "$emailSub";
                  $from = "[email protected]";
                  $body .= "<br />";
                  $body .= "$emailMsg<br /><br />";
                  $body .= "Regards FCP Team<br /><a href=\"http://www.firstchoicepharmacy.co.uk\">http://www.firstchoicepharmacy.co.uk</a>";
                  $headers = "MIME-Version: 1.0\r\n";  
                  $headers .= "From: firstchoicepharmacy.co.uk<$from>\n"; 
                  $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";  
     
                  $mail = mail($to,$subject,$body,$headers);
              }
         
         } // END WHILE
         
        } 
        
        if ($emailVal != "0")
        {
         // EMAIL INDIVIDUAL

                  $to = "$emailVal";
                  $subject = "$emailSub";
                  $from = "[email protected]";
                  $body .= "<br />";
                  $body .= "$emailMsg<br /><br />";
                  $body .= "Regards FCP Team<br /><a href=\"http://www.firstchoicepharmacy.co.uk\">http://www.firstchoicepharmacy.co.uk</a>";
                  $headers = "MIME-Version: 1.0\r\n";  
                  $headers .= "From: firstchoicepharmacy.co.uk<$from>\n"; 
                  $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";  
     
                  $mail = mail($to,$subject,$body,$headers);
            
        } 
      
        // Success
        if ($mail)
        {
          print("<br /><span class=\"mail_ok\"><img src=\"images/tick.png\"> You have successfully emailed [ <b>$emailVal</b> ]</span><br /><br /><br />");          
        } 
       
     // }
    
    } // End main isset
  
  break;
?>

 

This is an e-mail we sent today:

 

Dear Mr.XXXXXXXXXX

\r\n

\r\nThe ultramol capsules are out of stock .The suppliers can\'t indicate when the item will be back in stock. If you would like us to remove the charge for the ultramol capsules off the invoice and send out the remaining order, please let us know. If you would like us to cancel the whole order also please let us know and we will refund the charge back on to your card. We apologise for the inconvenience caused.

\r\n

\r\nBest Regards

\r\n

\r\nFCP Team

 

what would be the proper way to deal with data so its displkayed neatly lol

 

thanks for any help

 

Graham

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.