I have the following code and it will create a text file and email it to the desired recipient.
however i can not send text body.
There are two fields $email_txt and $email_message i am trying to get $email_txt into the $email_message which currently is sending the file
Please help
Code: Select all
if($_POST['emailThis'] == '1')
{
//get the grpid for this item
$check = mysql_query("SELECT *
FROM groups
WHERE GRP_phone = '$_POST[phone]' and GRP_email = '$_POST[email]'
limit 1")or die(mysql_error());
$info = mysql_fetch_array( $check );
//--------------------
//create text file
$ourFileName = "../company/emailfile/sample.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);
//
//edit temp file
$myFile = "../company/emailfile/sample.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "contents of my text file";
//
//email temp file
$fileatt = "../folder/emailfile/sample.txt"; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = "index.cmrl"; // Filename that will be used for the file as the attachment
$email_from = "Sales@company.com"; // Who the email is from
$email_subject = "Welcome to company.com"; // The Subject of the email
[color=#FF0000] $email_txt = "This email contains the index.cmrl file that you will need to put in the root directory of your web server."; // Message that the email has in it
[/color]
$email_to = "$_POST[email]"; // Who the email is too
$headers = "From: ".$email_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}\"";
[color=#FF0000] $email_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" .
$email_message . "\n\n";[/color]
$data = chunk_split(base64_encode($data));
[color=#FF0000] $email_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";[/color]
$ok = @mail($email_to, $email_subject, [color=#FF8000]$email_message[/color], $headers);//$email_txt is not currenty in anything but everytime i add it i get an error
if($ok) {
} else {
die("Sorry but the email could not be sent. Please go back and try again!");
}
}