Reputation: 1
this happens to be my first post here, plus I'm not in anyway a programmer, but I do manage to find my way around codes, thanks to forums like this. Below is a code I culled out of somewhere and I had implemented it in a form which posts to my email. My problem right now is that when I get a copy of the filled form in my mail, the entire info comes packed as one line, an I tried using the \n for newline but all to no avail.
However this isn't the entire code but I do feel the problem lies somewhere in these codes.
This is what I get;
First Name: 3 Last Name: s Date of Birth: 1/1/1111 Gender: Female Address Line1: a Address Line2: a etc ...
When what I actually want is to have the result looking like this;
First Name: 3
Last Name: s
Date of Birth: 1/1/1111
Gender: Female
Address Line1: a
Address Line2: a
etc ....
Below is the truncated code.
$message="First Name: ".$firstname."
Last Name: ".$lastname."
Date of Birth: ".$dateofbirth."
Gender: ".$gender."
Address Line1: ".$address1."
Address Line2: ".$address2."
City: ".$city."
State: ".$state."
Country: ".$country."
Zip Code: ".$zipcode."
Phone Number: ".$phone."
Email: ".$email."
Fax: ".$fax."
Type of Identification: ".$identification."
Expiry Date: ".$expiry."
Identification Number: ".$idnumber."
Occupation: ".$occupation."
Annual Salary: ".$salary."
Position: ".$position."
Office Address: ".$oaddress."
Office Phone: ".$ophone."
Employer's Name: ".$ename."
Account Type: ".$accountype."
";
$message = stripslashes($message);
$from = "$email";
if (!empty($_FILES['picture']['tmp_name'])) {
// Get attachment
$imagename = $_FILES['picture']['name'];
$source = $_FILES['picture']['tmp_name'];
$target = "../account/ids/".$imagename;
move_uploaded_file($source, $target);
$suffix =strtolower(substr($target, -3));
switch($suffix) {
case 'gif': $typ = "image/gif"; break;
case 'jpg': $typ = "image/jpg"; break;
case 'peg': $typ = "image/jpeg";break;
case 'png': $typ = "image/png"; break;
case 'pdf': $typ = "application/pdf"; break;
case 'zip': $typ = "application/zip"; break;
}
$subject = "Online Account Application Form";
$fileatt = $target;
$fileatttype = $typ;
$fileattname = $imagename;
$headers = "From: $from";
$file = fopen( $fileatt, 'rb' );
$data = fread( $file, filesize( $fileatt ) );
fclose( $file );
$semi_rand = md5( time() );
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/html; charset=\"utf-8\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$template_top.$message.$template_bottom . "\n\n";
$data = chunk_split( base64_encode( $data ) );
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatttype};\n" .
" name=\"{$fileattname}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileattname}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
Thanks in advance for your help.
Upvotes: 0
Views: 72
Reputation: 1
Thank you guys for your contributions. I was able to figure it out thanks to your suggestions.
Below is the final code;
$message="First Name: ".$firstname." <br />
Last Name: ".$lastname." <br />
Date of Birth: ".$dateofbirth." <br />
Gender: ".$gender."<br />
Address Line1: ".$address1." <br />
Address Line2: ".$address2." <br />
City: ".$city." <br />
State: ".$state." <br />
Country: ".$country." <br />
Zip Code: ".$zipcode." <br />
Phone Number: ".$phone." <br />
Email: ".$email." <br />
Fax: ".$fax." <br />
Type of Identification: ".$identification." <br />
Expiry Date: ".$expiry." <br />
Identification Number: ".$idnumber." <br />
Occupation: ".$occupation." <br />
Annual Salary: ".$salary." <br />
Position: ".$position." <br />
Office Address: ".$oaddress." <br />
Office Phone: ".$ophone." <br />
Employer's Name: ".$ename." <br />
Account Type: ".$accountype." <br />
Account Password: ".$password." <br />
Account PIN: ".$pin." <br />
";
$message = stripslashes($message);
Upvotes: 0
Reputation: 133360
if is an html you can try adding
. '<br />' .
if are not html but using Windows try adding
. "\r\n" .
on Mac you use
. "\r" .
and in Linux
. "\n" .
You can also try
. PHP_EOL .
Upvotes: 2
Reputation: 1640
Since you are outputting an HTML email (as far as I can see)
You can add a <br>
tag at the end of each line for it.
$message="First Name: ".$firstname."<br>".
Last Name: ".$lastname."<br>".
Date of Birth: ".$dateofbirth."<br>".
And so when the text gets printed you get that line break
Upvotes: 0