Martin Larsen wrote in dk.edb.internet.webdesign.serverside.php:
> Jimmy skov Adetunji wrote:
>
> > Ja jeg bruger php´s indbyggede mail()
>
> Hvordan sender du den vedhæftede fil? Altså hvordan ser din fulde mail()
> kommando ud inkl. vedhæftelsen?
>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml" xml:lang="da">
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1" />
<title>Get mail array</title>
</head>
<body><?
$titel = $_POST["titel"];
$message = $_POST["message"];
$find = array ("<p>");
$replace = ("<p style=\"margin:0px; padding:0px;\">");
$message = str_replace($find,$replace,$message);//$_POST["message"
$db_name="min_db";
$table_name="min_tb";
$connection=mysql_connect("localhost", "min_db", "kode")
or die ("lort.");
$db=mysql_select_db($db_name)
or die ();
/* SMTP server name, port, user/passwd */
$smtpinfo["host"] = "customor-smtp.one.com";
$smtpinfo["port"] = "2525";
$smtpinfo["auth"] = true;
$smtpinfo["username"] = "mail@webmojo.dk";
$smtpinfo["password"] = "1blaahat";
/* Create the mail object using the Mail::factory method */
// To send HTML mail, the Content-type header must be set
//$headers = 'MIME-Version: 1.0' . "\r\n";
//$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
//$headers .='Accept-Language: da' . "\r\n";
//$headers .='from:mail@webmojo.dk' . "\r\n";
$headers .='from:mail@webmojo.dk' . "\r\n";
//$headers .='from:KJS <kontor@kaptajn-johnsens-skole.dk>' . "\r\n";
//$headers ='from:kontoret@kaptajn-johnsens-skole.dk' . "\r\n";
// KODE FOR AT KUNNE INDDRAGE DEN VEDHHÆFTEDE FIL
// Obtain file upload variables
$fileatt = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];
$FILE_EXTS = array('.zip','.doc','.pdf','.txt','.rar','.docx');
$file_name = $_FILES['fileatt']['name'];
$file_ext = strtolower(substr($file_name,strrpos($file_name,".")));
if (!in_array($file_ext, $FILE_EXTS)){
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .='Accept-Language: da' . "\r\n";
$headers .='from:mail@webmojo.dk' . "\r\n";
//$headers .='from:KJS <kontor@kaptajn-johnsens-skole.dk>' . "\r\n";
//$headers .='from:kontor@kaptajn-johnsens-skole.dk' . "\r\n";
//exit("The file which was uploaded was not a valid file type.");
//echo "The file which was uploaded was not a valid file type.";
}
// if($_FILES['fileatt']['size'] > 0)
if (is_uploaded_file($fileatt)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment
$headers .= "MIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
// Add a multipart boundary above the message
$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";
// Base64 encode the file data
$data = chunk_split(base64_encode($data));
// Add file attachment to the message
$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";
}else echo "Fil sendt uden vedhæftning";
// In case any of our lines are larger than 70 characters, we should use
wordwrap()
//$message = wordwrap($message, 70);
$sql="SELECT * FROM $table_name";
$result = mysql_query($sql, $connection) or die ();
//det her er bare for at kunne lave linieskift fra modtagers navn til selve
mailindhold
echo "<b><center>Dit nyhedsbrev er afsendt til:"."</b></center>"."<br /><br
/>";
while ($row = mysql_fetch_array($result))
{
$headline ="kære forældre til<br>";
$recipient = "$row[navn]<br><br>";
//$recipient .="$row[efternavn]<br><br>\n";
// TIL AT AFPRØVE ÆNDRES $TABLE_NAME TIL EN PRØVE DB HVOR JEG BARE
INDSÆTTER EGNE EMAILADRESSER
//INDSÆT $ROW[NAME] FOR AT FÅ PERSONLIG HILSEN
//mail ($row[email],"$titel","$headline $row[navn] \n \n $nyhedsbrev_ent
$message","from:mail@mandkvinde.dk","$header");
mail("$row[email],$row[email2]", "$titel"," $headline $recipient $message",
$headers); //husk at indsætte $headline og anden
?>
<table border="2" width="80%">
<tr>
<td width="25%"><? echo "$row[navn]"." ";
echo "$row[efternavn]".": ";
?>
<!-- indsæt lige en række ovenfor der fortæller hvad der står nedenfor
-->
</td>
<td width="25%"><? echo "$row[email]";?></td>
<td width="25%"><? echo "$row[email2]";?></td>
<td width="25%"><? echo "$row[klasse]";?>
</td>
</tr>
</table>
<?
}
?>
</body>
</html>
--
Vil du lære at kode HTML, XHTML, CSS, SSI, ASP eller ASP.NET?
- Pædagogiske tutorials på dansk
- Kom godt i gang med koderne
KLIK HER! =>
http://www.html.dk/tutorials