1

onsdag, 22. juli 2009, 17:46


Hej

Jeg er rimeligt ny på det her område, men har fundet et mail-attachment-script, som jeg skal have sat ind på min side - ikke som html, for siden har jeg lavet - skal bare have det sat ind som en formular på i det eksisterende html :)

Form:

<form name="filepost" method="post" action="upload_file.php" enctype="multipart/form-data" id="file">

<div align="center">
<table width="300" border="0" cellpadding="0" cellspacing="0">
<tr valign="bottom">
<td><div align="center">
<p align="left"><span class="style15">Navn:</span></p>
</div></td>
</tr>
<tr>
<td> <p align="left">
<input name="from" type="text" id="from" size="30">
</p></td>
</tr>
<tr valign="bottom">
<td><div align="center">
<p align="left"><span class="style15">Email address:</span></p>
</div></td>
</tr>
<tr>
<td class="frmtxt2"> <p align="left">
<input name="emaila" type="text" id="emaila" size="30">
</p></td>
</tr>
<tr valign="bottom">
<td><div align="center">
<p align="left"><span class="style15">Message:</span></p>
</div></td>
</tr>
<tr>
<td> <p align="left" id="message" name="message" cols="30">
<textarea name="message" cols="30" id="message"></textarea>
</p></td>
</tr>
<tr>
<td valign="bottom"><div align="center">
<p align="left"><span class="style15">Browse files:</span></p>
</div></td>
</tr>
<tr valign="bottom">
<td valign="bottom"> <p align="left">
<input name="filea" type="file" id="filea" size="30">
</p></td></tr>
<tr>
<td height="50" valign="middle">

<div align="left">
<input name="Submit2" type="submit" value="Submit" onClick="return CheckData45()">
</div></td>
</tr>
</table>
</div>
</form>



PHP:

<?PHP
if ($filea)
{

function mail_attachment ($from , $to, $subject, $message, $attachment){
$fileatt = $attachment; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$start= strrpos($attachment, '/') == -1 ? strrpos($attachment, '//') : strrpos($attachment, '/')+1;
$fileatt_name = substr($attachment, $start, strlen($attachment)); // Filename that will be used for the file as the attachment

$email_from = $from; // Who the email is from
$subject = "Ny demo";
$email_subject = $subject; // The Subject of the email
$email_txt = $message; // Message that the email has in it

$email_to = $to; // Who the email is to

$headers = "From: ".$email_from;

$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$msg_txt="\n\n Du har modtaget en ny mail fra $from";
$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}\"";
$email_txt .= $msg_txt;
$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_txt . "\n\n";
$data = chunk_split(base64_encode($data));
$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";

$ok = mail($email_to, $email_subject, $email_message, $headers);

if($ok)
{
echo "Filen blev sendt.";
unlink($attachment); // delete a file after attachment sent.
}
else
{
die("Der er opstået en fejl - din mail kunne ikke sendes. Prøv venligst igen!");
}
}

move_uploaded_file($_FILES["filea"]["tmp_name"],'temp/'.basename($_FILES['filea']['name']));
mail_attachment("$from", "demo@love-music.dk", "subject", "message", ("temp/".$_FILES["filea"]["name"]));
}
?>



Samlet form:

<?PHP
if ($filea)
{

function mail_attachment ($from , $to, $subject, $message, $attachment){
$fileatt = $attachment; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$start= strrpos($attachment, '/') == -1 ? strrpos($attachment, '//') : strrpos($attachment, '/')+1;
$fileatt_name = substr($attachment, $start, strlen($attachment)); // Filename that will be used for the file as the attachment

$email_from = $from; // Who the email is from
$subject = "Ny demo";
$email_subject = $subject; // The Subject of the email
$email_txt = $message; // Message that the email has in it

$email_to = $to; // Who the email is to

$headers = "From: ".$email_from;

$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$msg_txt="\n\n Du har modtaget en ny mail fra $from";
$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}\"";
$email_txt .= $msg_txt;
$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_txt . "\n\n";
$data = chunk_split(base64_encode($data));
$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";

$ok = mail($email_to, $email_subject, $email_message, $headers);

if($ok)
{
echo "Filen blev sendt.";
unlink($attachment); // delete a file after attachment sent.
}
else
{
die("Der er opstået en fejl - din mail kunne ikke sendes. Prøv venligst igen!");
}
}

move_uploaded_file($_FILES["filea"]["tmp_name"],'temp/'.basename($_FILES['filea']['name']));
mail_attachment("$from", "demo@love-music.dk", "subject", "message", ("temp/".$_FILES["filea"]["name"]));
}
?>


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>

<script language="javascript" type="text/javascript">
function CheckData45()
{

with(document.filepost)
{

if(filea.value != "")
{
document.getElementById('one').innerText = "Attaching File ... Please Wait";
}
}
}
</script>


</head>

<body>

<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="top">


<form name="filepost" method="post" action="file.php" enctype="multipart/form-data" id="file">
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr valign="bottom">
<td height="20">Name:</td>
</tr>
<tr>
<td><input name="from" type="text" id="from" size="30"></td>
</tr>
<tr valign="bottom">
<td height="20">Email Address:</td>
</tr>
<tr>
<td class="frmtxt2"><input name="emaila" type="text" id="emaila" size="30"></td>
</tr>
<tr>
<td> <p align="left" id="message" name="message" cols="30">
<textarea name="message" cols="30" id="message"></textarea>
</p></td>
</tr>
<tr>
<td height="20" valign="bottom">Browse Files:</td>
</tr>
<tr valign="bottom">
<td valign="bottom"><input name="filea" type="file" id="filea" size="16"></td>
</tr>
<tr>
<td height="40" valign="middle"><input name="Reset2" type="reset" id="Reset2" value="Reset">
<input name="Submit2" type="submit" value="Submit" onClick="return CheckData45()"></td>
</tr>
</table>
</form>
<center>
<table width="400">
<tr>
<td id="one">
</td>
</tr>
</table>
</center>

</td>
</tr>
</table>


Du kan finde den originale kilde her:

http://www.phpmagicbook.com/upload-file-…l-format-email/

Håber ikke det er alt for uoverskueligt :)

På forhånd tak...

Hilsen
Anders

Dette indlæg er blevet redigeret 2 gange, senest redigeret af "dupreelove" (22.07.2009, 17:49)


2

onsdag, 29. juli 2009, 02:04


Jeg forstår ikke helt problemet?

Du har html og php-script klar. Så sæt det ind. :crazyeyes:

MSI ATX Intel 865PE Chipset || 120GB Seagate HDD, 10.700 rpm
512MB elixir DDR RAM || geForce Fx5200 128MB RAM :S
LG CD-R brænder 52x12x48x || AOC 19'' CRT

Nyeste Videoer og Trailers

Indsend nyhed
Har du fundet en fed nyhed så indsend den så alle andre på Tweak.dk kan få glæde af den.