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?
Related
Is there any issue with my below codes?
I'm trying to add an image as an attachment to HTML mail send it from my form. Users have an option to add images and on click of submit button it will be uploaded and sent.
But an error occurs on click of submit and within seconds it automatically redirects to success page, but no email is sent from the form. If there any mistakes in my code could someone clean the code and point out the mistakes I have done?
Thanks
require_once "Mail.php";
$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/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
$message .= "--{$mime_boundary}\n";
// preparing attachments
$file = fopen($filename,"rb");
$data = fread($file,filesize($filename));
fclose($file);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"".$fname."\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"$fname\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$message .= "--{$mime_boundary}--\n";
$Subject = Trim(stripslashes($_POST['Subject']));
$Name = Trim(stripslashes($_POST['Name']));
$filename = "/uploads/" . $_FILES["file"]["name"];
$Email = Trim(stripslashes($_POST['Email']));
$EmailMe = 'shmshd12#gmail.com';
$ip = $_SERVER['REMOTE_ADDR'];
$filename="/uploads/file.jpeg";
$fname="file.jpeg";
$Messages = Trim(stripslashes($_POST['Message']));
$smtp = Mail::factory('smtp', array(
'host' => 'host',
'port' => '##',
'auth' => true,
'username' => 'mail#example.com',
'password' => '*********',
));
$Body = "<html> html email</html>";
$Body1 = "<html> html email</html>";
$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}\"";
$headers .= "From: Roberta <request#robertalollobrigida.ga> \r\n";
$headers .= "Reply-To: < reply#example.com > \r\n";
$headers .= "Return-Path: user#example.com";
$headers .= "X-Mailer: PHP \r\n";
$message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
$message .= "--{$mime_boundary}\n";
// preparing attachments
$file = fopen($filename,"rb");
$data = fread($file,filesize($filename));
fclose($file);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"".$fname."\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"$fname\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$message .= "--{$mime_boundary}--\n";
$success = mail($Email, $Subject, $message, $headers, "-f " . $from);
mail($EmailMe, $Subject, $message, $ip, $headers, "-f " . $from);
if (success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=/thanks\">";
}
else{
echo "<meta http-equiv=\"refresh\" content=\"0;URL=/error\">";
}
i think its better to use PHPMailer
ot withot look to this example from php.net
There differenece in body, headers of email (with attachment, without
attachment), see this complete example below: work great for me (LINUX
, WIN) and (Yahoo Mail, Hotmail, Gmail, ...)
<?php
$to = $_POST['to'];
$email = $_POST['email'];
$name = $_POST['name'];
$subject = $_POST['subject'];
$comment = $_POST['message'];
$To = strip_tags($to);
$TextMessage =strip_tags(nl2br($comment),"<br>");
$HTMLMessage =nl2br($comment);
$FromName =strip_tags($name);
$FromEmail =strip_tags($email);
$Subject =strip_tags($subject);
$boundary1 =rand(0,9)."-"
.rand(10000000000,9999999999)."-"
.rand(10000000000,9999999999)."=:"
.rand(10000,99999);
$boundary2 =rand(0,9)."-".rand(10000000000,9999999999)."-"
.rand(10000000000,9999999999)."=:"
.rand(10000,99999);
for($i=0; $i < count($_FILES['youfile']['name']); $i++){
if(is_uploaded_file($_FILES['fileatt']['tmp_name'][$i]) &&
!empty($_FILES['fileatt']['size'][$i]) &&
!empty($_FILES['fileatt']['name'][$i])){
$attach ='yes';
$end ='';
$handle =fopen($_FILES['fileatt']['tmp_name'][$i], 'rb');
$f_contents =fread($handle, $_FILES['fileatt']['size'][$i]);
$attachment[]=chunk_split(base64_encode($f_contents));
fclose($handle);
$ftype[] =$_FILES['fileatt']['type'][$i];
$fname[] =$_FILES['fileatt']['name'][$i];
}
}
/***************************************************************
Creating Email: Headers, BODY
1- HTML Email WIthout Attachment!! <<-------- H T M L ---------
***************************************************************/
#---->Headers Part
$Headers =<<<AKAM
From: $FromName <$FromEmail>
Reply-To: $FromEmail
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="$boundary1"
AKAM;
#---->BODY Part
$Body =<<<AKAM
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="$boundary1"
This is a multi-part message in MIME format.
--$boundary1
Content-Type: text/plain;
charset="windows-1256"
Content-Transfer-Encoding: quoted-printable
$TextMessage
--$boundary1
Content-Type: text/html;
charset="windows-1256"
Content-Transfer-Encoding: quoted-printable
$HTMLMessage
--$boundary1--
AKAM;
/***************************************************************
2- HTML Email WIth Multiple Attachment <<----- Attachment ------
***************************************************************/
if($attach=='yes') {
$attachments='';
$Headers =<<<AKAM
From: $FromName <$FromEmail>
Reply-To: $FromEmail
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="$boundary1"
AKAM;
for($j=0;$j<count($ftype); $j++){
$attachments.=<<<ATTA
--$boundary1
Content-Type: $ftype[$j];
name="$fname[$i]"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="$fname[$j]"
$attachment[$j]
ATTA;
}
$Body =<<<AKAM
This is a multi-part message in MIME format.
--$boundary1
Content-Type: multipart/alternative;
boundary="$boundary2"
--$boundary2
Content-Type: text/plain;
charset="windows-1256"
Content-Transfer-Encoding: quoted-printable
$TextMessage
--$boundary2
Content-Type: text/html;
charset="windows-1256"
Content-Transfer-Encoding: quoted-printable
$HTMLMessage
--$boundary2--
$attachments
--$boundary1--
AKAM;
}
/***************************************************************
Sending Email
***************************************************************/
$ok=mail($To, $Subject, $Body, $Headers);
echo $ok?"<h1> Mail Sent</h1>":"<h1> Mail not SEND</h1>";
?>
This php script works just fine sending my pdf file by e-mail.
The problem is the script doesn't send any message as specified in $mainMessage.
Why do that problem occur, with the script only sending the pdf file without any message?
// Settings
$name = "Name";
$email = "someome#anadress.com";
$to = "$name <$email>";
$from = "email#email.com";
$subject = "Here is your attachment";
$mainMessage = "Hi, here's the file.";
$fileatt = "test.pdf";
$fileatttype = "application/pdf";
$fileattname = "newname.pdf";
$headers = "From: $from";
// File
$file = fopen($fileatt, 'rb');
$data = fread($file, filesize($fileatt));
fclose($file);
// This attaches the 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/plain; charset=\"iso-8859-1\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$mainMessage . "\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";
// Send the email
if(mail($to, $subject, $message, $headers)) {
echo "The email was sent.";
}
else {
echo "There was an error sending the mail.";
}
Try using \r\n instead of your \ns. Also, I would suggest using a library for sending emails, such as PHPMailer or SwiftMailer, instead.
EDIT: There appears to be an extra (or missing) " when you declare your charset (at "Content-Type: text/plain; charset=\"iso-8859-1\n" - it outputs Content-Type: text/plain; charset="iso-8859-1).
you didn't notice that you need to complete this line:
$message = "This is a multi-part message in MIME format.\r\n" .
"--{$mime_boundary}\r\n" .
"Content-Type: text/plain; charset=utf-8 \r\n" .
"Content-Transfer-Encoding: 7bit\r\n" .
$mainMessage . "\r\n\r\n";
you are missing one "-" in "-{$mime_boundary}\r\n".
it should be as the example I wrote :3
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";
This is the code am using to send an email with a doc file attached to it,
am receiving the email but the content in the email is displaying in a encoded text format
<?php
$to = $_POST['to'];
$from = $_POST['from'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$fileatt = $_FILES['upload_file']['tmp_name'];
$fileatt_type = $_FILES['upload_file']['type'];//application/msword
$fileatt_name = $_FILES['upload_file']['name'];
$headers = "From: $from";
if (is_uploaded_file($fileatt)) {
$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/plain; 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: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
mail($to, $subject, $message, $headers);
?>
email am receiving is like this
message:This is a multi-part message in MIME format. --==Multipart_Boundary_x788f8ac40875c8c7a6540be6654be9c8x Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit --==Multipart_Boundary_x788f8ac40875c8c7a6540be6654be9c8x Content-Type: application/msword; name="File_name.doc" Content-Disposition: attachment; filename="File_name.doc" Content-Transfer-Encoding: base64 s pcEAW4AJBAAA+BK/AAAAAAAAEAAAAAAACAAAMhMAAA4AYmpiaqz6rPoAAAAAAAAAAAAAAAAAAAAA AAAJBBYAuEAAAM6QAQDOkAEAFwsAAAAAAAAaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//w8AAAAA AAAAAAD//w8AAAAAAAAAAAD//w8AAAAAAAAAAAAAAAAAAAAAALcAAAAAAEgHAAAAAAAASAcAAIsU AAAAAAAAixQAAAAAAACLFAAAAAAAAIsUAAAAAAAAixQAADQAAAAAAAAAAAAAAP////8AAAAAvxQA AAAAAAC/FAAAAAAAAL8UAABoAAAAJxUAAEwAAABzFQAAbAAAAL8UAAAAAAAAj0UAAMYCAADfFQAA FgAAAPUVAAAQAAAABRYAAAAAAAAFFgAAAAAAAAUWAAAAAAAAJBcAACYAAABKFwAADAAAAFYXAAAI AAAADkUAAAIAAAAQRQAAAAAAABBFAAAAAAAAEEUAAAAAAAAQRQAAAAAAABBFAAAAAAAAEEUAACQA AABVSAAAogIAAPdKAAA8AAAANEUAABUAAAAAAAAAAAAAAAAAAAAAAAAAixQAAAAAAABeFwAAAAAA AAAAAAAAAAAAAAAAAAAAAAAkFwAAAAAAACQXAAAAAAAAXhcAAAAAAABeFwAAAAAAADRFAAAAAAAA AAAAAAAAAACLFAAAAAAAAIsUAAAAAAAABRYAAAAAAAAAAAAAAAAAAAUWAAAfAQAASUUAABYAAADc GgAAAAAAANwaAAAAAAAA3BoAAAAAAABeFwAADAEAAIsUAAAAAAAABRYAAAAAAACLFAAAAAAAAAUW AAAAAAAADkUAAAAAAAAAAAAAAAAAANwaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAXhcAAAAAAAAORQAAAAAAAAAAAAAAAAAA3BoAAAAAAADcGgAA pgEAAJY+AAAwAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKkIAAAAAAAAFFgAAAAAAAP////8AAAAA0NGIQpry zAEAAAAAAAAAAL8UAAAAAAAAahgAACIAAADGPwAAJAAAAAAAAAAAAAAA+kQAABQAAABfRQAAMAAA AI9FAAAAAAAA6j8AAEACAAAzSwAAAAAAAIwYAABQAgAAM0sAAEgAAAAqQgAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAADNLAAAAAAAAAAAAAAAAAACLFAAAAAAAACpCAADQAgAAXhcAAAAAAABeFwAAAAAAANwa AAAAAAAAXhcAAAAAAABeFwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAXhcA AAAAAABeFwAAAAAAAF4XAAAAAAAANEUAAAAAAAA0RQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAA== --==Multipart_Boundary_x788f8ac40875c8c7a6540be6654be9c8x--
headers:From: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="==Multipart_Boundary_x788f8ac40875c8c7a6540be6654be9c8x"
So can anyone help me with a perfect code
Thank u in advance
Find out the reason yourself by really debugging the issue at hand instead of guessing:
Dump the messages content you generate into a text file.
Dump any valid messages content you received in an email client into a file (the messages SOURCE code).
Compare both files and take your answer from the difference.
That works, really.
PHP doesn't support default utf-8 encoding, you need to pass the relevant encoding function as given in the following to your headers
Replace your code
Content-Type: text/plain; charset=\"iso-8859-1\"\n
to
"Content-Type:text/html;charset=utf-8"
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.