I have a mail script that allows attachments, and it is working fine, my problem is mainly an aesthetic one. When it sends the email, the lines of $message are all on one line in the body of the email, and not being separated.

Name : John Doe Email : john@john.com Job : boring Additional Information : Ok how about now? file.doc

i would like

Name
Email
Job
Additional Information

If anyone can spot where my mistake is i would appreciate it greatly, I need to walk away for a bit.

<?php 
require_once 'rnfunctions.php';

$id= $_GET['id'];


$query = "SELECT * FROM jobs WHERE id='$id'";
$result = mysql_query($query);

if (!$result) die ("Database access failed: " . mysql_error());

$rows = mysql_num_rows($result);
$row = mysql_fetch_row($result);

$to=$row[4];

// MAIL SUBJECT 


$fname=ucfirst($_REQUEST["fname"]); 
$lname=ucfirst($_REQUEST["lname"]); 
$email=ucfirst($_REQUEST["email"]); 
$addition=ucfirst($_REQUEST["addition"]);        

$replyTo = $email;
$from = $_POST['fname'] . " " . $_POST['lname'];
$subject = "Application for : " . $row[1];	

$strresume_name=$_FILES["strresume"]["name"]; 
$strresume_type=$_FILES["strresume"]["type"]; 
$strresume_size=$_FILES["strresume"]["size"]; 
$strresume_temp=$_FILES["strresume"]["tmp_name"]; 



if($strresume_type=="application/octet-stream" or $strresume_type=="text/plain" or $strresume_type=="application/msword" or $strresume_type=="application/pdf") 
{ 

$message	= "\r\n\r\n" . 'Name : ' . $from . "\r\n\r\n" . 'Email : ' . $email . "\r\n\r\n" . 'Job : ' . $row[1] . "\r\n\r\n" . 'Additional Information : ' . $addition . "\r\n\r\n";

// MAIL HEADERS with attachment 

$fp = fopen($strresume_temp, "rb"); 
$file = fread($fp, $strresume_size); 

$file = chunk_split(base64_encode($file)); 
$num = md5(time()); 

    //Normal headers 

$headers  = "From:" . $from . "\r\n"; 
   $headers  .= "MIME-Version: 1.0" . "\r\n"; 
   $headers  .= "Content-Type: multipart/mixed; "; 
   $headers  .= "boundary=".$num."\r\n"; 
   $headers  .= "--$num\r\n"; 

    // This two steps to help avoid spam    

$headers .= "Message-ID: <".gettimeofday()." TheSystem@".$_SERVER['SERVER_NAME'].">\r\n"; 
$headers .= "X-Mailer: PHP v".phpversion()."\r\n";         

    // With message 

$headers .= "Content-Type: text/html; charset=iso-8859-1" .  "\r\n"; 
   $headers .= "Content-Transfer-Encoding: 8bit\r\n"; 
   $headers .= "".$message."\n"; 
   $headers .= "--".$num."\n";  

    // Attachment headers 

$headers  .= "Content-Type:".$strresume_type." "; 
   $headers  .= "name=\"".$strresume_name."\"r\n"; 
   $headers  .= "Content-Transfer-Encoding: base64\r\n"; 
   $headers  .= "Content-Disposition: attachment; "; 
   $headers  .= "filename=\"".$strresume_name."\"\r\n\n"; 
   $headers  .= "".$file."\r\n"; 
   $headers  .= "--".$num."--"; 



// SEND MAIL 

   @mail($to, $subject, $message, $headers); 


 fclose($fp); 

echo 'Attachment has been sent Successfully.'; 
} 
else 
    { 
        echo 'Wrong file format. Mail was not sent.'; 

} 

?>

I have experimented with different \n \r\n and even <br> but sometimes the body information doesn't even display.

Thank You in advance.

-Ben

    you really shouldn't use php built in mail() for anything but the most basic mail. it is very limited in its functionality.

    PHPMailer or another class would be a better place to start

    Note: If intending to send HTML or otherwise Complex mails, it is recommended to use the PEAR package » PEAR::Mail_Mime.

      I know, however I am still learning and would like to know why my mistakes are creating the problems that they are so I can not just use someones code, but if I am not writing it, I can understand how it is working incase I need to customize or change it.

        fixed it myself, thank you for anyone who looked at this.

          9 months later

          Can you post what you did for your fix I am struggling with the same issue.

            bungychicago please don't hijack an 8 month old thread, start a new one.

              Intent was not to hijack a year old thread just appears there was unfinished business I thought I would ask what the resolution would be.

              I figured out what I needed on my own. Any other people experiencing the issue described in this thread try <br /> for new line and <p /> for a double spaced line break.

                bungychicago;10977462 wrote:

                I figured out what I needed on my own. Any other people experiencing the issue described in this thread try <br /> for new line and <p /> for a double spaced line break.

                ok, but use the html properly

                  Write a Reply...