Click to See Complete Forum and Search --> : Sending form content to E-mail


toplisek
09-16-2005, 05:59 AM
Sending form content to E-mail Edit/Delete Message Reply w/Quote
I have form, which has SUBMIT button and would like to
send content of the form to E-mail address. What is procedure (script) to send this content per specific E-mail (MySQL and PHP).
I hope you can help

abectech
09-16-2005, 08:14 AM
www.php.net

Look up mail()

toplisek
09-16-2005, 10:28 AM
I have checked and posted code as following:
$address = '...;
$subject= '...';
$body="you got a message"
$mailsend = mail($address, $subject, $body);
echo $mailsend;
I'm new to this function. What should I put into code that it will send E-mail?
I hope you can help me

bokeh
09-16-2005, 12:04 PM
What you are trying to print is a boolean. Try this instead:
$address = 'recipient@domain.com';
$subject = 'subject text';
$body = 'body text'
$result = (mail($address, $subject, $body)) ? 'succeeded' : 'failed';
echo 'Sending mail to '.$address.' '.$result.'.';

758
09-16-2005, 01:21 PM
also, make sure to check to php.ini to make sure it is configured to send mail

toplisek
09-17-2005, 02:23 AM
thanks, now I understand. you are very helpful

toplisek
09-17-2005, 07:46 AM
I have also question how to determin:
"From: <someone@domain.com>"
if you have
$address = ''...'';
$subject= "...'';
$body= "...''
$result = (mail($address, $subject, $body)) ? 'succeeded' : 'failed';

felgall
09-17-2005, 05:46 PM
$address = ''...'';
$subject= "...'';
$body= "...'';
$headers= "From: ...";
$result = (mail($address, $subject, $body,$headers)) ? 'succeeded' : 'failed';

toplisek
09-20-2005, 05:18 AM
I have seen that in some E-mails there
is script:

$headers ='Content-type: multipart/alternative; boundary="Myweb.com_multipart_boundary____________";
$result = (mail($address, $subject, $body, $headers)) ? 'succeeded' : 'failed';

and code:
--Myweb_multipart_boundary____________
Content-Type: text/plain;

and also:
--Myweb_multipart_boundary____________
Content-Type: text/html;

how does this code work and what is correct script ?

bokeh
09-20-2005, 07:12 AM
Well if an email is to contain html, plain and attached parts those parts must be separated with a boundary string and the whole email must comply with the relevant rfc. Below I have posted a function which prints out finished emails in their various forms so you can look at the differences. By the way this function makes ready to read emails and is not for use in conjunction with mail();

<?php

// Build mime or plain content

// $email = fill in the recipient
$email = 'you@your-email.com';

// $email_from = fill in the the sender
$email_from = 'me@my-email.com';

// Fill in the subject
$subject = 'Subject';

// Fill in email body text. Can include html tags.
$email_body = 'Body text';

// Attachments
// Any attachment should look like the following and include
// the file name and the path. Add as many as you like.
// $attachments[] = 'c:/path/to/file/filename.ext';
// $attachments[] = 'c:/path/to/another/file/another-filename.ext';

// HTML mail
// Set to TRUE for HTML email with plain text alterative or FALSE for plain text email
$html = FALSE;

function mime_content($email, $email_from, $subject, $email_body, $html = NULL, &$attachments = NULL)
{

if (!function_exists('mime_content_type')){
function mime_content_type($file){
@$size = getimagesize($file);
if($size[mime]){
return($size[mime]);
}
return('application/octet-stream');
}
}
// Generate a boundary string
$mime_boundary = "mime_boundry_multipart/mixed".md5(time())."x";
$alternative_mime_boundary = "mime_boundry_multipart/alternative_".md5(time())."x";

$content = "Date: ".date('D, d M Y H:i:s O')."\n".
"Subject: $subject\n".
"To: $email\n".
"From: $email_from\n".
"MIME-Version: 1.0\n";

if(count($attachments) > 0){
$content .= "Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"\n\n";

if($html == TRUE){
$content .= "This is a multi-part message in MIME format.\n\n".
"--{$mime_boundary}\n".
"Content-Type: multipart/alternative;\n".
" boundary=\"{$alternative_mime_boundary}\"\n\n".
"--{$alternative_mime_boundary}\n".
"Content-Type: text/plain; charset=ISO-8859-1; format=flowed\n".
"Content-Transfer-Encoding: 7bit\n\n".
strip_tags($email_body)."\n\n".
"--{$alternative_mime_boundary}\n".
"Content-Type: text/html; charset=ISO-8859-1\n".
"Content-Transfer-Encoding: 7bit\n\n".
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n".
"<html>\n".
"<head>\n".
" <meta content=\"text/html;charset=ISO-8859-1\" http-equiv=\"Content-Type\">\n".
" <title></title>\n".
"</head>\n".
"<body>\n".
$email_body."\n".
"</body>\n".
"</html>\n\n".
"--{$alternative_mime_boundary}--\n";
}else{
$content .= "This is a multi-part message in MIME format.\n\n".
"--{$mime_boundary}\n".
"Content-Type: text/plain; charset=ISO-8859-1; format=flowed\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
strip_tags($email_body)."\n\n";
}



// Deal with attachments array
if(count($attachments) > 0){
foreach($attachments as $key => $value){
$mime_type = mime_content_type($value);
if(is_file($value)){
if(ereg('^image', $mime_type)){
$disposition = 'inline';
}else{
$disposition = 'attachment';
}
$filesize = filesize($value);
$file = fopen($value,'rb');
$data = fread($file,$filesize);
fclose($file);

// Base64 encode the file data
$data = chunk_split(base64_encode($data));
$value = pathinfo($value);
$content .= "--{$mime_boundary}\n" .
"Content-Type: $mime_type;\n" .
" name=\"{$value[basename]}\"\n" .
"Content-Transfer-Encoding: base64\n" .
"Content-Disposition: $disposition;\n" .
" filename=\"{$value[basename]}\"\n\n" .
$data . "\n";
}
}
}

$content .= "--{$mime_boundary}--\n";




}elseif($html == TRUE){
$content .= "Content-Type: multipart/alternative;\n".
" boundary=\"{$alternative_mime_boundary}\"\n\n".
"--{$alternative_mime_boundary}\n".
"Content-Type: text/plain; charset=ISO-8859-1; format=flowed\n".
"Content-Transfer-Encoding: 7bit\n\n".
strip_tags($email_body)."\n\n".
"--{$alternative_mime_boundary}\n".
"Content-Type: text/html; charset=ISO-8859-1\n".
"Content-Transfer-Encoding: 7bit\n\n".
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n".
"<html>\n".
"<head>\n".
" <meta content=\"text/html;charset=ISO-8859-1\" http-equiv=\"Content-Type\">\n".
" <title></title>\n".
"</head>\n".
"<body>\n".
$email_body."\n".
"</body>\n".
"</html>\n\n".
"--{$alternative_mime_boundary}--\n";


}else{
$content .= "Content-Type: text/plain; charset=ISO-8859-1; format=flowed\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
strip_tags($email_body)."\n";
}
return($content);
}

print '<pre>'.htmlspecialchars(mime_content($email, $email_from, $subject, $email_body, $html, $attachments)).'</pre>';

?>

toplisek
09-21-2005, 02:22 AM
Dear bokeh,
thanks. what do you mean
By the way this function makes ready to read emails and is not for use in conjunction with mail();
How to use this script? Is this to insert in my code? I'm new to this. Sorry.

bokeh
09-21-2005, 02:47 AM
That function produces output as it would appear in a .eml file.

bokeh
09-21-2005, 04:33 AM
Ok! The function above was just to show what a completed mail should look like. The following function will build and send mime mail with or without attachments. Just use it as a replacement for mail();
<?php
// function to send mime or plain email, with or without attachments

// $recipient = fill in the recipient
$recipient = 'you@your-email.com';

// $headers = fill in the the sender
$headers = 'From: me@my-email.com';

// Fill in the subject
$subject = 'Subject';

// Fill in email body text. Can include html tags.
$message = 'Body text';

// Attachments
// Any attachment should look like the following and include
// the file name and the path. Add as many as you like.
// $attachments[] = 'c:/path/to/file/filename.ext';

// HTML mail
// Set to TRUE to send HTML tags in the email body or FALSE for plain text email
$html = false;

send_mime_mail($recipient, $subject, $message, $headers, $html, $attachments);

function send_mime_mail($recipient, $subject, $message, $headers = NULL, $html = NULL, $attachments = NULL)
{

if (!function_exists('mime_content_type')){
function mime_content_type($file){
@$size = getimagesize($file);
if($size[mime]){
return($size[mime]);
}
return('application/octet-stream');
}
}
// Generate a boundary string
$mime_boundary = "mime_boundry_multipart/mixed".md5(time())."x";
$alternative_mime_boundary = "mime_boundry_multipart/alternative_".md5(time())."x";

if(empty($headers)) $headers = '';
$headers .= "\nMIME-Version: 1.0\n";

if(count($attachments) > 0){
$headers .= "Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"\n\n";

if(!empty($html) and $html == TRUE){
$content = "This is a multi-part message in MIME format.\n\n".
"--{$mime_boundary}\n".
"Content-Type: multipart/alternative;\n".
" boundary=\"{$alternative_mime_boundary}\"\n\n".
"--{$alternative_mime_boundary}\n".
"Content-Type: text/plain; charset=ISO-8859-1; format=flowed\n".
"Content-Transfer-Encoding: 7bit\n\n".
strip_tags($message)."\n\n".
"--{$alternative_mime_boundary}\n".
"Content-Type: text/html; charset=ISO-8859-1\n".
"Content-Transfer-Encoding: 7bit\n\n".
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n".
"<html>\n".
"<head>\n".
" <meta content=\"text/html;charset=ISO-8859-1\" http-equiv=\"Content-Type\">\n".
" <title></title>\n".
"</head>\n".
"<body>\n".
$message."\n".
"</body>\n".
"</html>\n\n".
"--{$alternative_mime_boundary}--\n";
}else{
$content = "This is a multi-part message in MIME format.\n\n".
"--{$mime_boundary}\n".
"Content-Type: text/plain; charset=ISO-8859-1; format=flowed\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
strip_tags($message)."\n\n";
}



// Deal with attachments array
if(count($attachments) > 0){
foreach($attachments as $key => $value){
$mime_type = mime_content_type($value);
if(is_file($value)){
if(ereg('^image', $mime_type)){
$disposition = 'inline';
}else{
$disposition = 'attachment';
}
$filesize = filesize($value);
$file = fopen($value,'rb');
$data = fread($file,$filesize);
fclose($file);

// Base64 encode the file data
$data = chunk_split(base64_encode($data));
$value = pathinfo($value);
$content .= "--{$mime_boundary}\n" .
"Content-Type: $mime_type;\n" .
" name=\"{$value[basename]}\"\n" .
"Content-Transfer-Encoding: base64\n" .
"Content-Disposition: $disposition;\n" .
" filename=\"{$value[basename]}\"\n\n" .
$data . "\n";
}
}
}

$content .= "--{$mime_boundary}--\n";




}elseif(!empty($html) and $html == TRUE){
$headers .= "Content-Type: multipart/alternative;\n".
" boundary=\"{$alternative_mime_boundary}\"\n\n";
$content = "--{$alternative_mime_boundary}\n".
"Content-Type: text/plain; charset=ISO-8859-1; format=flowed\n".
"Content-Transfer-Encoding: 7bit\n\n".
strip_tags($message)."\n\n".
"--{$alternative_mime_boundary}\n".
"Content-Type: text/html; charset=ISO-8859-1\n".
"Content-Transfer-Encoding: 7bit\n\n".
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n".
"<html>\n".
"<head>\n".
" <meta content=\"text/html;charset=ISO-8859-1\" http-equiv=\"Content-Type\">\n".
" <title></title>\n".
"</head>\n".
"<body>\n".
$message."\n".
"</body>\n".
"</html>\n\n".
"--{$alternative_mime_boundary}--\n";


}else{
$headers .= "Content-Type: text/plain; charset=ISO-8859-1; format=flowed\n" .
"Content-Transfer-Encoding: 7bit\n\n";
$content = strip_tags($message)."\n";
}
if(mail($recipient, $subject, $content, $headers)) return TRUE;
return FALSE;
}
?>

toplisek
09-22-2005, 08:54 AM
this is great. It works.
I have just question how to define that HTML will work?
I have <a href=1_help.php>Help Department</a> and it does not work but I have defined $html = true; (there is also $html = NULL )
there is NULL and why is there this position?
I hope you can help

bokeh
09-22-2005, 09:36 AM
Don't change this:function send_mime_mail($recipient, $subject, $message, $headers = NULL, $html = NULL, $attachments = NULL)
{ it is correct. Just paste the function to the bottom of your script or put it in an external file and call it but don't make any changes to it.

If you want to include html <tags> do it like this:

// set variables
$message = 'Here is a <a href="href://www.dogs.com">link</a>!';
$subject = 'Interesting link';
$recipient = 'recipient@domain.com';

// Now send it
send_mime_mail($recipient, $subject, $message, NULL, TRUE);


I haven't tested that but if you can't make it work tell me and I will run a test .

toplisek
09-22-2005, 10:01 AM
I have body and HTML does not work, I have put $html = true;This is the only change. It recognised variables but HTM link not. Can you maybe test?

$message = "$namesen requested we send you this e-mail including this personal note:<BR><BR>
Hello $fnamerec $lnamerec,<BR><BR>
$bodysen<BR><BR>
$namesen<BR><BR>

***********************************************************
<BR><BR>
$namesen asked us to send you this information.<BR>
Please visit our <a href=help.php>Help Department</a> for questions.<BR><BR>

***********************************************************";

bokeh
09-22-2005, 12:09 PM
I tried this:$message = $namesen.' requested we send you this e-mail including this personal note:<BR><BR>'."\n".
'Hello '.$fnamerec.$lnamerec.',<BR><BR>'."\n".
$bodysen.'<BR><BR>'."\n".
$namesen.'<BR><BR>'."\n".
"\n".
'***********************************************************'."\n".
'<BR><BR>'."\n".
$namesen.' asked us to send you this information.<BR>'."\n".
'Please visit our <a href="http://bokehman.com/captcha_verification">Help Department</a> for questions.<BR><BR>'."\n".
"\n".
'***********************************************************'."\n";

send_mime_mail($recipient, $subject, $message, NULL, TRUE);
Note: The <a> tag should contain a full and properly quoted URL. Also the $message string should be properly quoted. If you are too lazy to quote the string use heredoc syntax.

Anyway the above tests positive and the link is highlighted in the email. When the link is selected it operates as expected.

toplisek
09-23-2005, 03:34 AM
this works,
problem is that when is sent to e.g. yahoo it works link,
but when I receive in Netscape on my local it does not show link.
I receive normally HTML messages.

bokeh
09-23-2005, 03:40 AM
Ok. So what is happening is this. The link is present in the html version but not in the plain text version and your Netscape is looking at the plain text version. I am working on this at the moment so will re-post the function shortly with changes later.

bokeh
09-23-2005, 12:31 PM
Ok! Try this and report back:
function send_mime_mail($recipient, $subject, $message, $headers = NULL, $html = NULL, $attachments = NULL, $css = NULL)
{
if (!function_exists('mime_content_type')){
function mime_content_type($file){
if(!is_readable($file)) return false;
@$size = getimagesize($file);
if(!empty($size[mime])){
return($size[mime]);
}else{
$extensions = array('doc' => 'application/msword', 'html'=> 'text/html', 'htm' => 'text/html',
'pdf' => 'application/pdf', 'ppt' => 'application/vnd.ms-powerpoint', 'rtf' => 'text/rtf',
'xls' => 'application/vnd.ms-excel', 'zip' => 'application/zip');
$keys = array_keys($extensions);
$parts = array_reverse(explode('.', $file));
$extension = $parts['0'];
if(in_array($extension, $keys)) return $extensions[$extension];
$data = file_get_contents($filename);
$bad = false;
for($x = 0, $y = strlen($data); !$bad && $x < $y; $x++){
$bad = (ord($data{$x}) > 127);
}
if(!$bad) return ('text/plain');
return('application/octet-stream');
}
}
}
function convert_links($text)
{
$search = array(
'/<a\s[^>]*href=[\'"]mailto:([^\'"]+)[\'"][^>]*>([^<]+)<\/a>/i',
'/<a\s[^>]*href=mailto:([^\s>]+)[^>]*>([^<]+)<\/a>/i',
'/<a\s[^>]*href=[\'"](h?[ft]tp:[^\'"]+)[\'"][^>]*>([^<]+)<\/a>/i',
'/<a\s[^>]*href=(h?[ft]tp:[^\s>]+)[^>]*>([^<]+)<\/a>/i',
'/<a\s[^>]*>([^<]*)<\/a>/i');
$replace = array('\2 (\1)',
'\2 (\1)',
'\2 (\1)',
'\2 (\1)',
'\1');
return(strip_tags(preg_replace($search, $replace, $text)));
}

function html_to_plain($string)
{
$string = preg_replace("(\r\n|\n|\r)", ' ', $string);
$string = preg_replace('/<p>/i', "\n\n", $string);
$string = preg_replace('/(<br>|<br \/>)/i', "\n", $string);
return (convert_links($string));
}
if(!isset($css)) $css = '';
// Generate a boundary string
$mime_boundary = "mime_boundry_multipart/mixed".md5(time())."x";
$alternative_mime_boundary = "mime_boundry_multipart/alternative_".md5(time())."x";

if(empty($headers)) $headers = '';
$headers .= "\nMIME-Version: 1.0\n";

if(count($attachments) > 0){
$headers .= "Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"\n\n";

if(!empty($html) and $html == TRUE){
$content = "This is a multi-part message in MIME format.\n\n".
"--{$mime_boundary}\n".
"Content-Type: multipart/alternative;\n".
" boundary=\"{$alternative_mime_boundary}\"\n\n".
"--{$alternative_mime_boundary}\n".
"Content-Type: text/plain; charset=ISO-8859-1; format=flowed\n".
"Content-Transfer-Encoding: 7bit\n\n".
html_to_plain($message)."\n\n".
"--{$alternative_mime_boundary}\n".
"Content-Type: text/html; charset=ISO-8859-1\n".
"Content-Transfer-Encoding: 7bit\n\n".
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n".
"<html>\n".
"<head>\n".
" <style type=\"text/javascript\">\n".
" $css \n".
" </style>\n".
" <meta content=\"text/html;charset=ISO-8859-1\" http-equiv=\"Content-Type\">\n".
" <title></title>\n".
"</head>\n".
"<body>\n".
$message."\n".
"</body>\n".
"</html>\n\n".
"--{$alternative_mime_boundary}--\n";
}else{
$content = "This is a multi-part message in MIME format.\n\n".
"--{$mime_boundary}\n".
"Content-Type: text/plain; charset=ISO-8859-1; format=flowed\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
convert_links($message)."\n\n";
}



// Deal with attachments array
if(count($attachments) > 0){
foreach($attachments as $key => $value){
$mime_type = mime_content_type($value);
if(is_file($value) and is_readable($value) ){
if(ereg('^image', $mime_type)){
$disposition = 'inline';
}else{
$disposition = 'attachment';
}
$filesize = filesize($value);
$file = fopen($value,'rb');
$data = fread($file,$filesize);
fclose($file);

// Base64 encode the file data
$data = chunk_split(base64_encode($data));
$value = pathinfo($value);
$content .= "--{$mime_boundary}\n" .
"Content-Type: $mime_type;\n" .
" name=\"{$value['basename']}\"\n" .
"Content-Transfer-Encoding: base64\n" .
"Content-Disposition: $disposition;\n" .
" filename=\"{$value['basename']}\"\n\n" .
$data . "\n";
}
}
}

$content .= "--{$mime_boundary}--\n";




}elseif(!empty($html) and $html == TRUE){
$headers .= "Content-Type: multipart/alternative;\n".
" boundary=\"{$alternative_mime_boundary}\"\n\n";
$content = "--{$alternative_mime_boundary}\n".
"Content-Type: text/plain; charset=ISO-8859-1; format=flowed\n".
"Content-Transfer-Encoding: 7bit\n\n".
html_to_plain($message)."\n\n".
"--{$alternative_mime_boundary}\n".
"Content-Type: text/html; charset=ISO-8859-1\n".
"Content-Transfer-Encoding: 7bit\n\n".
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n".
"<html>\n".
"<head>\n".
" <style type=\"text/javascript\">\n".
" $css \n".
" </style>\n".
" <meta content=\"text/html;charset=ISO-8859-1\" http-equiv=\"Content-Type\">\n".
" <title></title>\n".
"</head>\n".
"<body>\n".
$message."\n".
"</body>\n".
"</html>\n\n".
"--{$alternative_mime_boundary}--\n";


}else{
$headers .= "Content-Type: text/plain; charset=ISO-8859-1; format=flowed\n" .
"Content-Transfer-Encoding: 7bit\n\n";
$content = convert_links($message)."\n";
}
if(mail($recipient, $subject, $content, $headers)) return TRUE;
return FALSE;
}

toplisek
09-24-2005, 02:45 AM
It is the same result. In Netscape I receive normally HTML messages. In your case there is no HTML link

bokeh
09-24-2005, 04:24 AM
What do you mean in my case. Did you add the code I posted. If not do so! When you receive the email in your mail client (e.g. outlook express) save it to the desktop with a .eml extention. Now open that file with a text editor and paste the contents to this forum. Once I see the output I will be able to tell if it is the email that has a problem or some other software you are using. When I tested this it worked fine. Obviously an HTML link can't work in plain text but the URL and link text were both present when I tested.

Post the email. I want the source, not the content.

toplisek
12-15-2005, 05:57 AM
Dear Bokeh,
please help me what to change that there wil be shown chartacters in Subject and in body like š and č :rolleyes:

What do you mean with code:
Subject: =?UTF-8?B?YWJjxIxkZWY=?=

I have changed to unicode but it does not work.


Your code which I have was :) :

<?PHP
// function to send mime or plain email, with or without attachments

// $recipient = fill in the recipient
$contactLink1 = '<a href="...contactus.php">contact us</a>';
$contactLink2 = '<a href="...help.php">Help Department</a>';
$recipient = "$emailrec";

// $headers = fill in the the sender
$headers = "From: $emailsen" . "\r\n" .
"Reply-To: $emailsen";

// Fill in the subject
$subject = "$namesen wants you to see you";

// Fill in email body text. Can include html tags.
$message = $namesen.' requested we send you this e-mail including this personal note:<BR><BR>'."\n".
'Hello '.$fnamerec.' '.$lnamerec.',<BR><BR>'."\n".
$bodysen.'<BR><BR>'."\n".
$namesen.'<BR><BR>'."\n".
"\n".
'***********************************************************'."\n".
'<BR><BR>'."\n".
$namesen.' asked us to send you this information.<BR>'."\n".
'If you are interested in any products or services,<BR>
do not hesitate to ' .$contactLink1. '.<BR>'."\n".
'<br />Please visit our ' .$contactLink2. ' for questions.<BR><BR>'."\n".
"\n".

'With our warmest regards,<BR><BR>'."\n".

'Our web site team<BR>'."\n".
'***********************************************************'."\n";



// Attachments
// Any attachment should look like the following and include
// the file name and the path. Add as many as you like.
// $attachments[] = 'c:/path/to/file/filename.ext';

// HTML mail
// Set to TRUE to send HTML tags in the email body or FALSE for plain text email
$html = true;

send_mime_mail($recipient, $subject, $message, $headers, $html, $attachments);

function send_mime_mail($recipient, $subject, $message, $headers = NULL, $html = NULL, $attachments = NULL, $css = NULL)
{

if (!function_exists('mime_content_type')){
function mime_content_type($file){
if(!is_readable($file)) return false;
@$size = getimagesize($file);
if(!empty($size['mime'])){
return($size['mime']);
}else{
$extensions = array('doc' => 'application/msword', 'html'=> 'text/html', 'htm' => 'text/html',
'pdf' => 'application/pdf', 'ppt' => 'application/vnd.ms-powerpoint', 'rtf' => 'text/rtf',
'xls' => 'application/vnd.ms-excel', 'zip' => 'application/zip');
$keys = array_keys($extensions);
$parts = array_reverse(explode('.', $file));
$extension = $parts['0'];
if(in_array($extension, $keys)) return $extensions[$extension];
$data = file_get_contents($filename);
$bad = false;
for($x = 0, $y = strlen($data); !$bad && $x < $y; $x++)
{
$bad = (ord($data{$x}) > 127);
}
if(!$bad) return ('text/plain');
return('application/octet-stream');
}
}
}
function convert_links($string, $protocol = TRUE)
{
$search[] = '/<a\s[^>]*href=[\'"]mailto:([^\'"]+)[\'"][^>]*>([^<]+)<\/a>/i';
$search[] = '/<a\s[^>]*href=mailto:([^\s>]+)[^>]*>([^<]+)<\/a>/i';
$search[] = '/<a\s[^>]*href=[\'"](http:\/\/[^\'"]+)[\'"][^>]*>([^<]+)<\/a>/i';
$search[] = '/<a\s[^>]*href=(http:\/\/[^\s>]+)[^>]*>([^<]+)<\/a>/i';
$replace = '\2 (\1)';
return(strip_tags(preg_replace($search, $replace, $string)));
}

function html_to_plain($string)
{
$string = preg_replace("(\r\n|\n|\r)", ' ', $string);
$string = preg_replace('/<p>/i', "\n\n", $string);
$string = preg_replace('/(<br>|<br \/>)/i', "\n", $string);
return (convert_links($string));
}
if(!isset($css)) $css = '';
// Generate a boundary string
$mime_boundary = "mime_boundry_multipart/mixed".md5(time())."x";
$alternative_mime_boundary = "mime_boundry_multipart/alternative_".md5(time())."x";

if(empty($headers)) $headers = '';
$headers .= "\nMIME-Version: 1.0\n";

if(count($attachments) > 0){
$headers .= "Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"\n\n";

if(!empty($html) and $html == TRUE){
$content = "This is a multi-part message in MIME format.\n\n".
"--{$mime_boundary}\n".
"Content-Type: multipart/alternative;\n".
" boundary=\"{$alternative_mime_boundary}\"\n\n".
"--{$alternative_mime_boundary}\n".
"Content-Type: text/plain; charset=iso-8859-1; format=flowed\n".
"Content-Transfer-Encoding: 7bit\n\n".
html_to_plain($message)."\n\n".
"--{$alternative_mime_boundary}\n".
"Content-Type: text/html; charset=iso-8859-1\n".
"Content-Transfer-Encoding: 7bit\n\n".
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n".
"<html>\n".
"<head>\n".
" <style type=\"text/javascript\">\n".
" $css \n".
" </style>\n".
" <meta content=\"text/html;charset=iso-8859-1\" http-equiv=\"Content-Type\">\n".
" <title></title>\n".
"</head>\n".
"<body>\n".
$message."\n".
"</body>\n".
"</html>\n\n".
"--{$alternative_mime_boundary}--\n";
}else{
$content = "This is a multi-part message in MIME format.\n\n".
"--{$mime_boundary}\n".
"Content-Type: text/plain; charset=iso-8859-1; format=flowed\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
convert_links($message)."\n\n";
}



// Deal with attachments array
if(count($attachments) > 0){
foreach($attachments as $key => $value){
$mime_type = mime_content_type($value);
if(is_file($value) and is_readable($value) ){
if(ereg('^image', $mime_type)){
$disposition = 'inline';
}else{
$disposition = 'attachment';
}
$filesize = filesize($value);
$file = fopen($value,'rb');
$data = fread($file,$filesize);
fclose($file);

// Base64 encode the file data
$data = chunk_split(base64_encode($data));
$value = pathinfo($value);
$content .= "--{$mime_boundary}\n" .
"Content-Type: $mime_type;\n" .
" name=\"{$value['basename']}\"\n" .
"Content-Transfer-Encoding: base64\n" .
"Content-Disposition: $disposition;\n" .
" filename=\"{$value['basename']}\"\n\n" .
$data . "\n";
}
}
}

$content .= "--{$mime_boundary}--\n";




}elseif(!empty($html) and $html == TRUE){
$headers .= "Content-Type: multipart/alternative;\n".
" boundary=\"{$alternative_mime_boundary}\"\n\n";
$content = "--{$alternative_mime_boundary}\n".
"Content-Type: text/plain; charset=iso-8859-1; format=flowed\n".
"Content-Transfer-Encoding: 7bit\n\n".
html_to_plain($message)."\n\n".
"--{$alternative_mime_boundary}\n".
"Content-Type: text/html; charset=iso-8859-1\n".
"Content-Transfer-Encoding: 7bit\n\n".
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n".
"<html>\n".
"<head>\n".
" <style type=\"text/javascript\">\n".
" $css \n".
" </style>\n".
" <meta content=\"text/html;charset=iso-8859-1\" http-equiv=\"Content-Type\">\n".
" <title></title>\n".
"</head>\n".
"<body>\n".
$message."\n".
"</body>\n".
"</html>\n\n".
"--{$alternative_mime_boundary}--\n";


}else{
$headers .= "Content-Type: text/plain; charset=iso-8859-1; format=flowed\n" .
"Content-Transfer-Encoding: 7bit\n\n";
$content = convert_links($message)."\n";
}
if(mail($recipient, $subject, $content, $headers)) return TRUE;
return FALSE;
}
?>

bokeh
12-15-2005, 06:54 AM
Did you actually try running that code I posted as the subject? If not do so and you will see how it works.$subject = '=?UTF-8?B?YWJjxIxkZWY=?=';Here's the code to do that or similar:$subject = 'Espaņol';
$charset = 'ISO-8859-1';
$subject_encoded = '=?'.$charset.'?B?' . base64_encode($subject) . '?=';
print $subject_encoded;

toplisek
12-15-2005, 09:01 AM
$subject = '=?UTF-8?B?YWJjxIxkZWY=?=';

If I have variable and text:
$subject = "$namesen wants you to see you";

How to put into yout code?
I'm new to this, please suggest.

bokeh
12-15-2005, 09:20 AM
$subject = '=?UTF-8?B?YWJjxIxkZWY=?=';

If I have variable and text:
$subject = "$namesen wants you to see you";

How to put into yout code?
I'm new to this, please suggest.Are you serious? Have you read my post above? That was just an example for insertion into mail(). Did you try it?<?php

$subject = $namesen.' wants you to see you';
$charset = 'ISO-8859-1';
$subject_encoded = '=?' . $charset . '?B?' . base64_encode($subject) . '?=';

?>