Kirim attachment file dengan php
Untuk kirim attachment file ada penambahan script dari yang biasa kita mengirim email tanpa
attachment file berikut ini script untuk attachment file beserta dengan html dan bisa langsung
di gunakan :
<?
$adminEmail = "$_POST[adminEmail]";
if($_POST['submit']) {
$to = $_POST['to'];
$subject = $_POST['subject'];
$pengantar=$_POST[pengantar];
$pengantarok =
"Dear ".ucfirst(strtolower($_POST['Salutation']))."".ucfirst(strtolower($_POST['Suren
ame'])).",<br><br>";
$pengantarok2 = "$pengantar<br><br>";
$pesan = "<table width=700 border=0 cellpadding=0 cellspacing=0 align=center>
<tr><td height='10'></td></tr>
<tr><td>$pengantarok</td></tr><tr><td>$pengantarok2</td></tr><tr><td>
<table width=700 border=0 cellspacing=0 cellpadding=0>
<tr>
<td height=25></td>
</tr>
</table>
</td></tr></table>";
$attach = $_FILES['file1']['tmp_name'];
$attach_type = $_FILES['file1']['type'];
$attach_name = $_FILES['file1']['name'];
$headers = "From: $adminEmail";
// Generate string untuk batas (boundary)
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Tambahkan header untuk file yang akan dikirim
$headers .= "
MIME-Version: 1.0
" .
"Content-Type: multipart/mixed;
" .
" boundary="{$mime_boundary}"";
// Tambahkan pesan
$message .= "Ini adalah pesan berbentuk multi-part dalam format MIME format.
" .
"--{$mime_boundary}
" .
"Content-Type: text/html; charset="iso-8859-1"
" .
"Content-Transfer-Encoding: 7bit
" .
$pesan . "
";
$message .= "--{$mime_boundary}
";
// Apabila ada file yang di attach
if (is_uploaded_file($attach)) {
// Baca file yang akan di attach/kirim ('rb' = read binary)
$file = fopen($attach,'rb');
$data = fread($file,filesize($attach));
fclose($file);
// Untuk transisi data gunakan base64_encode();
$data = chunk_split(base64_encode($data));
// Tambahkan pesan pada file yang dikirim.
$message .= "Content-Type: {$attach_type};
" . "
name="$attach_name"
" .
"Content-Transfer-Encoding: base64
" . $data . "
";
$message .= "--{$mime_boundary}
";
}
$body = "$message";
mail($to, $subject, $body, $headers);
echo '<b>Your mail had been send to '.$to.' recipients</b>';
} else {
?>
<form name="letter" action="" method="post" enctype="multipart/form-data">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td width="23%">Salutation</td>
<td width="77%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><input type="radio" name="Salutation" value="Mr.">Mr. <input type="radio" name="Salutation" value="Mrs.">Mrs.</font></td>
</tr>
<tr><td colspan="2" height="10"></td></tr>
<tr>
<td width="23%">Name To</td>
<td width="77%"><input name="Surename" type="text" id="Surename" size="35" style="font-weight:bold" onFocus="this.value='';" value="isi sure name"></td>
</tr>
<tr><td colspan="2" height="10"></td></tr>
<tr>
<td width="23%">Email To</td>
<td width="77%"><input name="to" type="text" id="to" size="35"
style="font-weight:bold" onFocus="this.value='';" value="isi to"></td>
</tr>
<tr><td colspan="2" height="10"></td></tr>
<tr>
<td>Subject</td>
<td>
<input name="subject" type="text" id="subject" size="60" style="font-weight:bold" value=""></td>
</tr>
<tr><td colspan="2" height="10"></td></tr>
<tr>
<td>From Email</td>
<td>
<input name="adminEmail" type="text" id="adminEmail" size="60" style="font-weight:bold" value=""></td>
</tr>
<tr><td colspan="2" height="10"></td></tr>
<tr>
<td>Pengantar Kata</td>
<td><textarea name="pengantar" id="pengantar" rows="15" cols="80" style="width:50%"></textarea></td>
</tr>
<tr><td colspan="2" height="10"></td></tr>
<tr><td colspan="2" height="10"></td></tr>
<tr>
<td>Attach File</td>
<td><input type="file" name="file1"></td>
</tr>
<tr><td colspan="2" height="10"></td></tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Send Mail"></td>
</tr>
</table>
</form>
<? } ?>
| mkgfzcwoemn, ugkmju@gpfksd.com |
|
| 14/12/2011 23:12:58 |
|
|
gUGLXI , [url=http://zpaqrfmzznzl.com/]zpaqrfmzznzl[/url], [link=http://nfouskdwghyw.com/]nfouskdwghyw[/link], http://zxuetgqxfbmj.com/ |
|
|
| bgfhrujs, yfvprb@oloilo.com |
|
| 14/12/2011 23:12:21 |
|
|
S4PI5w , [url=http://hurtsqqndmqi.com/]hurtsqqndmqi[/url], [link=http://ogbcgwqhbsvp.com/]ogbcgwqhbsvp[/link], http://oryxlpgtjfjk.com/ |
|
|
| khnvkyb, rbzfcq@yqfpir.com |
|
| 14/12/2011 18:12:22 |
|
|
21QuVH bcnvyroavmsp |
|
|
| txkhrc, nhnhqj@ubeonu.com |
|
| 14/12/2011 02:12:28 |
|
|
zU2hPU fjqhutcjqyah |
|
|
| Eddi, p.skoprepron@mail.be |
|
| 14/12/2011 00:12:00 |
|
|
Yo, that`s what`s up truthuflly. |
|
|
| Chamomile, webmaster@tsjl.net |
|
| 13/12/2011 22:12:41 |
|
|
I went to tons of links boefre this, what was I thinking? |
|
|
|
|
|