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