Send CSV file attached to the email - php

I have an issue: i need to create csv file and send it attached to the particular emails.
Honestly i never do that so i'm quite a lammer in this matter. Can anybody tell me with what i have to start or share some links?

I think this what you are looking for, i've used it in the past works perfectly.
Hope it helps.
<?php
$cr = "\n";
$csvdata = "First Name" . ',' . "Last Name" . $cr;
$csvdata .= $txtFName . ',' . $txtLName . $cr;
$thisfile = 'file.csv';
$encoded = chunk_split(base64_encode($csvdata));
// create the email and send it off
$subject = "File you requested from RRWH.com";
$from = "scripts#rrwh.com";
$headers = 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-Type: multipart/mixed;
boundary="----=_NextPart_001_0011_1234ABCD.4321FDAC"' . "\n";
$message = '
This is a multi-part message in MIME format.
------=_NextPart_001_0011_1234ABCD.4321FDAC
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Hello
We have attached for you the PHP script that you requested from http://rrwh.com/scripts.php
as a zip file.
Regards
------=_NextPart_001_0011_1234ABCD.4321FDAC
Content-Type: application/octet-stream; name="';
$message .= "$thisfile";
$message .= '"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="';
$message .= "$thisfile";
$message .= '"
';
$message .= "$encoded";
$message .= '
------=_NextPart_001_0011_1234ABCD.4321FDAC--
';
// now send the email
mail($email, $subject, $message, $headers, "-f$from");
?>
Kind regards,
Wesley.

Related

send PHP mail with Content-Type: multipart/alternative

I am trying to send a multipart mail that contains both html and plain text. This is also one of the ways to get through spam filters and to allow more people to read the mail in case of not supporting HTML. After spending long hours googling, I have found some examples. I made my code, which sends the mail but it displays the text with the html tags, code, string etc.
<?php
$boundary=md5(uniqid(rand()));
$header .= "From:My Name<something#something.com>\n";
$header .= "Reply-To: something#something.com \n";
$header .= 'MIME-Version: 1.0'."\r\n";
$header .= 'Content-type: multipart/alternative;boundary=$boundary '."\n";
$adres = "something#gmail.com";
$subject = "subject";
$message = "This is multipart message using MIME\n";
$message .= "--" . $boundary . "\n";
$message .= "Content-type: text/plain;charset=iso-8859-1\n";
$message .= "Content-Transfer-Encoding: 7bit". "\n\n";
$message .= "Plain text version\n\n";
$message .="--" . $boundary . "\n";
$message .="Content-type: text/html;charset=iso-8859-1\n";
$message .= "Content-Transfer-Encoding: 7bit". "\n\n";
$message .="<html>
<body>
<center>
<b>HTML text version</b>
</center>
</body>
</html>\n\n";
$message .= "--" . $boundary . "--";
if(mail($adres, $subject, $message, $header))
{
print'message sent';
}
else
{
print'message was not sent';
}
?>
This is the result:
This is multipart message using MIME
--c071adfa945491cac7759a760ff8baeb
Content-type: text/plain;charset=iso-8859-1
Content-Transfer-Encoding: 7bit
Plain text version
--c071adfa945491cac7759a760ff8baeb
Content-type: text/html;charset=iso-8859-1
Content-Transfer-Encoding: 7bit
<html>
<body>
<center>
<b>HTML text version</b>
</center>
</body>
</html>
--c071adfa945491cac7759a760ff8baeb--
As you can see it displays the coding instead of the message alone. I have tried many solutions posted like:
adding/removing \r\n;
changing \r\n to \n;
changing content type from alternative to mixed;
I am learning PHP and all I know is all I have read and done so far. I have still much to learn so please if you could tell me where is the problem. I would be very thankful.Best regards.
The line:
$header .= 'Content-type: multipart/alternative;boundary=$boundary '."\n";
Has the wrong quotes, so $boundary won't be expanded. Change to:
$header .= "Content-type: multipart/alternative;boundary=$boundary\n";
And like I said in the comments, in the message headers and the content section headers you should be using \r\n as the line break since that's what is defined in the RFC. Most MTAs will allow simply \n, but some will choke on the message, and some spam filters will count every RFC violation as a point towards your spam score.
Using something like PHPMailer is a much better option because it formats everything perfectly by default, and abides by just about every single obscure, boring RFC.
I think you need quotes around the boundary string.
try this:
$header .= 'Content-type: multipart/alternative; boundary="' . $boundary . '"\r\n';
Try this example https://github.com/breakermind/PhpMimeParser/blob/master/PhpMimeClient_class.php
$m = new PhpMimeClient();
// Add to
$m->addTo("email#star.ccc", "Albercik");
$m->addTo("adela#music.com", "Adela");
// Add Cc
$m->addCc("zonk#email.au");
// Add Bcc
$m->addBcc("boos#domain.com", "BOSS");
// Add files inline
$m->addFile('photo.jpg',"zenek123");
// Add file
$m->addFile('sun.png');
// create mime
$m->createMime("Witaj!",'<h1>Witaj jak się masz? <img src="cid:zenek123"> </h1>',"Wesołych świąt życzę!","Heniek Wielki", "hohoho#domain.com");
// get mime
// $m->getMime();
// Show mime
echo nl2br(htmlentities($m->getMime()));
Here is the complete script without errors:
<?php
error_reporting(-1);
ini_set("display_errors", "1");
$mailto = "email#enter-domainname-here.com";
$subject = "subject";
$boundary=md5(uniqid(rand()));
$header = "From:Info<".$mailto.">\n";
$header .= "Reply-To: ".$mailto."\n";
$header .= "MIME-Version: 1.0"."\n";
$header .= "Content-type: multipart/alternative; boundary=\"----=_NextPart_" . $boundary . "\"";
$message = "This is multipart message using MIME\n";
$message .= "------=_NextPart_" . $boundary . "\n";
$message .= "Content-Type: text/plain; charset=UTF-8\n";
$message .= "Content-Transfer-Encoding: 7bit". "\n\n";
$message .= "Plain text version\n\n";
$message .="------=_NextPart_" . $boundary . "\n";
$message .="Content-Type: text/html; charset=UTF-8\n";
$message .= "Content-Transfer-Encoding: 7bit". "\n\n";
$message .="<html>
<body>
<center>
<b>HTML text version</b>
</center>
</body>
</html>\n\n";
$message .= "------=_NextPart_" . $boundary . "--";
if(#mail($mailto, $subject, $message, $header))
{
print'message sent';
}
else
{
print"message was not sent";
}
?>

Emailing CSV file with PHP

I have extracted data from my database and displayed it on a webpage in table format. I provided a link on this page which allows the user to download this data as a CSV file. This works correctly so far and when the user follows the link beneath the displayed data it allows them to save it.
It also sends an email with the CSV as an attachment. However currectly the CSV in the attachment is blank and I dont know why.
All i want is for the data from the database which is placed into a downloadable CSV to also go into the attached CSV and I cant do it.
Could someone help me?
Here is the code I have so far:
// Create CSV file
fputcsv($output, array('Name', 'Branch', 'Website','Company', 'Question1', 'Question2', 'Question3', 'Question4', 'Question5'));
$mysql_connection = db_connect_enhanced('*******','******','******','******');
$query='SELECT * FROM ****.****';
$surveys = db_query_into_array_enhanced($mysql_connection, $query);
$count = count($surveys);
$data = array();
for($i=0; $i<=$count; $i++){
$data[] = array($surveys[$i]['FeedbackName'], $surveys[$i]['BranchName'], $surveys[$i]['FeedbackWebsite'], $surveys[$i]['FeedbackCompany'], $surveys[$i]['Question1'], $surveys[$i]['Question2'], $surveys[$i]['Question3'], $surveys[$i]['Question4'], $surveys[$i]['Question5']);
}
foreach( $data as $row )
{
fputcsv($output, $row, ',', '"');
}
$encoded = chunk_split(base64_encode($data));
// create the email and send it off
$subject = "File you requested from RRWH.com";
$from = "***************";
$headers = 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-Type: multipart/mixed;
boundary="----=_NextPart_001_0011_1234ABCD.4321FDAC"' . "\n";
$message = '
This is a multi-part message in MIME format.
------=_NextPart_001_0011_1234ABCD.4321FDAC
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Hello
We have attached for you the PHP script that you requested from http://rrwh.com/scripts.php
as a zip file.
Regards
------=_NextPart_001_0011_1234ABCD.4321FDAC
Content-Type: application/octet-stream; name="';
$message .= "surveys.csv";
$message .= '"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="';
$message .= "surveys.csv";
$message .= '"
';
$message .= "$encoded";
$message .= '
------=_NextPart_001_0011_1234ABCD.4321FDAC--
';
mail("*************", $subject, $message, $headers, "-f$from");
fclose($output);
It feels like I am so close but I just cant see the answer :(
Change this line:
$message .= "$encoded";
With this one:
$message .= $encoded;
This is only a "SUGGESTIVE" answer:
Here is what I use to attach files and it works for me and it may help you to "BASE" yourself with the problem you're having.
$file_path = "/path_to_your/$file_name";
$file_path_name = "$file_name"; // this file name will be used at receiver end
$file = fopen($file_path,'rb');
$data = fread($file,filesize($file_path));
fclose($file);
$rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$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=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message .= "\n\n";
$data = chunk_split(base64_encode($data));
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$file_path_type};\n" .
" name=\"{$file_path_name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$file_path_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data .= "\n\n" .
"--{$mime_boundary}--\n";

PHP mail function - attachment coming as text

I know there are lot posts related to PHP mail function. But seriously i couldn't figure out what's wrong with my code below:
$subject = "New article submitted.";
$message = "You've received this e-mail through your website's write an article form: \n";
$message .= "Name: {$data['username']} \n";
$message .= "E-mail: {$data['email']} \n";
$message .= "\nRegards,\nAakriti \n";
$headers = "From: {$data['name']} <{$data['email']}> \n";
// Boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
// Add a multipart boundary above the plain message
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain;\n charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n" .
"--{$mime_boundary}\n";
// preparing attachments
for($i=0;$i < count($_FILES['articledata']['name']); $i++) {
// store the file information to variables for easier access
$tmp_name = $_FILES['articledata']['tmp_name'][$i];
$type = $_FILES['articledata']['type'][$i];
$name = $_FILES['articledata']['name'][$i];
$size = $_FILES['articledata']['size'][$i];
$file = fopen($tmp_name,"rb");
$attachment = fread($file,filesize($tmp_name));
fclose($file);
$attachment = chunk_split(base64_encode($attachment));
print_r($attachment);
//$attachment = chunk_split(base64_encode(file_get_contents($tmp_name)));
$message .= "Content-Type: {$type};\n" .
" name=\"{$name}\"\n" .
"Content-Transfer-Encoding: base64\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$name}\"\n\n" .
$attachment . "\n" .
"--{$mime_boundary}\n";
$message .= "--\n\n";
}
$headers .= "Reply-To: <{$data['email']}>";
if (mail($recipient,$subject,$message,$headers)) {
echo "<p>Thank you! Your mail was successfully sent to the webmaster. Thank you for your time.</p>";
} else {
echo "<p>Sorry, there was an error and your mail was not sent. Please find an alternative method of contacting the webmaster.</p>";
}
It just doesn't work as intended. Attachment is comes out as some binary text. Take a look below:
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="==Multipart_Boundary_xf6a3dd3e1c0c1f9233b8c66ce2a73e3ex"Reply-To: <test03#gmail.com>
This is a multi-part message in MIME format.
--==Multipart_Boundary_xf6a3dd3e1c0c1f9233b8c66ce2a73e3ex
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
You've received this e-mail through your website's write an article form:
Name: Johnson
E-mail: test#gmail.com
Regards,
Aakriti
--==Multipart_Boundary_xf6a3dd3e1c0c1f9233b8c66ce2a73e3ex
Content-Type: image/jpeg;
name="599307_322143481199958_2058932593_n.jpg"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="599307_322143481199958_2058932593_n.jpg"
/9j/4AAQSkZJRgABAgAAAQABAAD//gAEKgD/4gIcSUNDX1BST0ZJTEUAAQEAAAIMbGNtcwIQAABt
bnRyUkdCIFhZWiAH3AABABkAAwApADlhY3NwQVBQTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
9tYAAQAAAADTLWxjbXMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAApkZXNjAAAA/AAAAF5jcHJ0AAABXAAAAAt3dHB0AAABaAAAABRia3B0AAABfAAAABRyWFla
AAABkAAAABRnWFlaAAABpAAAABRiWFlaAAABuAAAABRyVFJDAAABzAAAAEBnVFJDAAABzAAAAEBi
VFJDAAABzAAAAEBkZXNjAAAAAAAAAANjMgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB0ZXh0AAAA
AEZCAABYWVogAAAAAAAA9tYAAQAAAADTLVhZWiAAAAAAAAADFgAAAzMAAAKkWFlaIAAAAAAAAG+i
AAA49QAAA5BYWVogAAAAAAAAYpkAALeFAAAY2lhZWiAAAAAAAAAkoAAAD4QAALbPY3VydgAAAAAA
AAAaAAAAywHJA2MFkghrC/YQPxVRGzQh8SmQMhg7kkYFUXdd7WtwegWJsZp8rGm/fdPD6TD////b
AEMABgQEBQQEBgUFBQYGBgcJDgkJCAgJEg0NCg4VEhYWFRIUFBcaIRwXGB8ZFBQdJx0fIiMlJSUW
HCksKCQrISQlJP/bAEMBBgYGCQgJEQkJESQYFBgkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQk
JCQkJCQkJCQkJCQkJCQkJCQkJCQkJP/CABEIAS8B4AMAIgABEQECEQH/xAAbAAACAwEBAQAAAAAA
AAAAAAAABQIDBAEGB//EABgBAQEBAQEAAAAAAAAAAAAAAAABAgME/8QAGAEBAQEBAQAAAAAAAAAA
AAAAAAECAwT/2gAMAwAAARECEQAAAfqgAAAHAPOabh2Vwm7+QWo06vqZa9w57WxTTLsFDRJ
UPDATE: Finally got it fixed after breaking my head for hours..
there were couple of problems:
As pointed out by asachanfbd mime
boundary was not properly nested.
This was one is silly & yet it was the main culprit - extra line breaks at below line of code:
$message .= "\nRegards,\nAakriti \n";
$headers = "From: {$data['name']} <{$data['email']}> \n";
Thanks everyone!
Not much of an answer to your question, but
you could have a look on PHPMailer and on its example.
It is pretty easy to add attachments with PHPMailer.
In a mail mime boundary is used to enclose different part of the mail. In your implementation you did not enclosed body of the mail in required mime type. Also keep in mind that mime boundary for the mail needs to be same for entire mail.
You can use these set of functions for easy implementation.
http://pastebin.com/AbZjzYdv

php mail: attachments errors

people!
I've gotta send messages with attachments.
So i've got some code based on some examples from internet:
$path = $_SERVER['DOCUMENT_ROOT'] . ATTACHMENT_DIR . DS;
$files = array('filename1.ext', 'filename2.ext');
$EOL = "\r\n"; // "\n";
$to = "mail#domain.tld";
$from = '=?UTF-8?B?' . base64_encode($_POST['name']) . '?=' . " <" . $_POST['email'] . ">";
$subject = "subject";
$subject = '=?UTF-8?B?' . base64_encode($subject) . '?=';
$message = $_POST['message'];
$mime_boundary = md5(uniqid(time()));
$headers .= "From: $from" .
"{$EOL}MIME-Version: 1.0{$EOL}" .
"Content-Type: multipart/mixed; boundary=\"{$mime_boundary}\"{$EOL}{$EOL}" .
"This is a multi-part message in MIME format.{$EOL}" .
"-–{$mime_boundary}{$EOL}" .
"Content-Type: text/plain; charset=UTF-8{$EOL}" .
"Content-Transfer-Encoding: 8bit{$EOL}{$EOL}" .
$message . "{$EOL}{$EOL}";
// preparing attachments
for ($x = 0; $x < count($files); $x++) {
$file = fopen($path . $files[$x], "rb");
$data = fread($file, filesize($path . $files[$x]));
fclose($file);
$data = chunk_split(base64_encode($data), 72, $EOL);
$headers .= "-–{$mime_boundary}{$EOL}" .
"Content-Type: application/octet-stream; name=\"$files[$x]\"{$EOL}" .
"Content-Transfer-Encoding: base64{$EOL}{$EOL}" .
"Content-Disposition: attachment; filename=\"$files[$x]\"{$EOL}" .
$data . "{$EOL}";
}
$headers .= "--{$mime_boundary}--{$EOL}";
$result = #mail($to, $subject, "", $headers);
It works, but something is going wrong. This code generates:
To: mail#domain.tld
Subject: =?UTF-8?B?c3ViamVjdA==?=
From: =?UTF-8?B?Sm9obiBEb2U=?= <mail#domail.tld>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="2dd88e9ef3ae338d9e93bc8448a74093"
This is a multi-part message in MIME format.
-–2dd88e9ef3ae338d9e93bc8448a74093
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
test message
-–2dd88e9ef3ae338d9e93bc8448a74093
Content-Type: application/octet-stream; name="filename1.ext"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="filename1.ext"
R0lGODlhMgAyAPf/ALsoJpcZFeG8wZsoJb+NiKZDQMV6eKgYFqpJR6lWVdKtq6oeHP7//9a0
[cutted]
Qx66WAxbFOMNs8gDJAohCr5Svd8mUEgM7oAI7HghBRMJra6XEhAAOw==
-–2dd88e9ef3ae338d9e93bc8448a74093
Content-Type: application/octet-stream; name="filename2.ext"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="filename2.ext"
R0lGODlhMgAyAPf/ALsoJpcZFeG8wZsoJb+NiKZDQMV6eKgYFqpJR6lWVdKtq6oeHP7//9a0
[cutted]
Qx66WAxbFOMNs8gDJAohCr5Svd8mUEgM7oAI7HghBRMJra6XEhAAOw==
--2dd88e9ef3ae338d9e93bc8448a74093--
Message recieved without text or any attachments. Please, help me find suitable solution!
I'm blaming the base64_encode.
Try the code at http://www.zedwood.com/article/126/php-mail-function-with-attachments instead and see if that works better.
Any particular reason you're not using Mail_Mime?

What is wrong with this mail header text?

The following $header is being sent via PHP's mail($to,$subject,$content,$header) command. The mail arrives and appears to have an attachment. But the mail text is empty as is the file. I think this has something to do with line spacing but I can't see the problem. I have tried putting the contents (between the boundaries) in $contents rather than appending it to $header. It doesn't make a difference. Any thoughts?
From: dnagirl#someplace.com
Reply-To: dnagirl#someplace.com
X-Mailer: PHP 5.3.1
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="7425195ade9d89bc7492cf520bf9f33a"
--7425195ade9d89bc7492cf520bf9f33a
Content-type:text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 7bit
this is a test message.
--7425195ade9d89bc7492cf520bf9f33a
Content-Type: application/pdf; name="test.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="test.pdf"
JVBERi0xLjMKJcfsj6IKNSAwIG9iago8PC9MZW5ndGggNiAwIFIvRmlsdGVyIC9GbGF0ZURlY29k
ZT4+CnN0cmVhbQp4nE2PT0vEMBDFadVdO4p/v8AcUyFjMmma5CqIIF5cctt6WnFBqLD1+4Np1nY3
c3lvfm+GyQ4VaUY11iQ2PTyuHG5/Ibdx9fIvhi3swJMZX24c602PTzENegwUbNAO4xcoCsG5xuWE
.
... the rest of the file
.
MDAwMDA2MDYgMDAwMDAgbiAKMDAwMDAwMDcwNyAwMDAwMCBuIAowMDAwMDAxMDY4IDAwMDAwIG4g
CjAwMDAwMDA2NDcgMDAwMDAgbiAKMDAwMDAwMDY3NyAwMDAwMCBuIAowMDAwMDAxMjg2IDAwMDAw
IG4gCjAwMDAwMDA5MzIgMDAwMDAgbiAKdHJhaWxlcgo8PCAvU2l6ZSAxNCAvUm9vdCAxIDAgUiAv
SW5mbyAyIDAgUgovSUQgWzxEMURDN0E2OUUzN0QzNjI1MDUyMEFFMjU0MTMxNTQwQz48RDFEQzdB
NjlFMzdEMzYyNTA1MjBBRTI1NDEzMTU0MEM+XQo+PgpzdGFydHhyZWYKNDY5MwolJUVPRgo=
--7425195ade9d89bc7492cf520bf9f33a--
$header ends without a line break
I use the code below to send a message with an attachment as well as html and text message parts. I remember fighting with it a long time to get it right, but unfortunately don't remember which parts were my problems. Maybe looking at it will help you out. I've changed some irrelevant variables and hopefully made it easier to read. Feel free to ask if something is weird or unclear and I'll try to explain.
public function sendEmail($htmlString)
{
$random_hash = md5(date('r', time()));
$message = "--mixed-$random_hash\n";
$message .= 'Content-Type: multipart/alternative; boundary="alt-' . $random_hash . '"' . "\n\n";
$message .= 'MIME-Version: 1.0' . "\n";
$message .= '--alt-' . $random_hash . "\n";
$message .= 'Content-Type: text/plain; charset="iso-8859-1"' . "\n";
$message .= 'Content-Transfer-Encoding: 7bit' . "\n\n";
// text message
$message .= strip_tags($htmlString) . "\n\n";
$message .= '--alt-' . $random_hash . "\n";
$message .= 'Content-Type: text/html; charset="iso-8859-1"' . "\n";
$message .= 'Content-Transfer-Encoding: 7bit' . "\n\n";
// html message
$message .= $htmlString . "\n\n";
$message .= '--alt-' . $random_hash . '--' . "\n";
// graph image
if($this->selectedGraph != 0)
{
$graphString = $this->getGraph(); // image attachment
$graphString = chunk_split(base64_encode($graphString));
$linkID = 'graph-' . $userInfo['FirmID'] . $random_hash . '-image';
$message .= '--mixed-' . $random_hash . "\n";
$message .= 'MIME-Version: 1.0' . "\n";
$message .= 'Content-Transfer-Encoding: base64' . "\n";
$message .= 'Content-ID: ' . $linkID . "\n";
$message .= 'Content-Type: image/gif; name="graph.gif"' . "\n";
$message .= 'Content-Disposition: attachment' . "\n\n";
$message .= $graphString;
$message .= '--mixed-' . $random_hash . '--' . "\n";
}
else
{
$message .= '--mixed-' . $random_hash . '--' . "\n";
}
$headers = 'From: ' . $this->from. "\r\nReply-To: " . $this->replyto;
$headers .= "\r\nContent-Type: multipart/related; boundary=\"mixed-" . $random_hash . "\"\r\nMIME-Version: 1.0";
$flags = '-f ' . BOUNCED_EMAIL_ADDRESS;
return mail($userInfo['Email'], $this->subject, $message, $headers, $flags);
}
These things happen when building mime mails from scratch. There are a couple of php modules you can use to generate cool and compatible mime messages. Mail_Mime should do the trick.

Categories