|
|
|
รบกวนหน่อยค่ะ เรื่อง Email Attachment Files TT-TT |
|
|
|
|
|
|
|
ลองทำดูแล้วนะค่ะ แต่ไฟล์ที่ไปคือ ไฟล์สุดท้าย มีเพียงไฟล์เดียว ไฟลือื่นไม่มีเลยอ่าค่ะ TT^TT
|
|
|
|
|
Date :
2009-11-10 11:47:03 |
By :
kasilot |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
code นี้อ่าค่ะ ผิดตรงไหนอ่าค่ะ ช่วยดูให้หน่อยค่ะ
Code (PHP)
<?
require("class.phpmailer.php");
$resume = $_FILES['Resume']['name'];
$comment = $_FILES['comment']['name'];
//echo $resume;
//echo $comment;
if ($resume AND $comment == null){
$emailTo = "[email protected]";
$emailSubject = "JOB!";
$emailName = $_REQUEST['fm_name'];
$emailFrom = $_REQUEST['fm_email'];
$send_mail=mail($emailTo,$emailSubject,$emailName,$emailFrom);
if(!$send_mail)
{
echo"<center><br> Send Complete 1 <br></center>";
//echo "<meta http-equiv='refresh' content=2;URL=apply.html>";
}
else{
echo"<center><br> Send Fail 1 <br></center>";
//echo "<meta http-equiv='refresh' content=2;URL=apply.html>";
}
}else{
$emailTo = "[email protected]";
$emailSubject = "JOB!";
$boundary = md5(uniqid(time()));
$emailHeader = "From: " . $_POST['fm_email'] . "\n";
$emailHeader .= "Content-Type: multipart/mixed; boundary=$boundary\n";
$emailMsg = "--$boundary\n";
$emailMsg .= "Content-Type: text/plain; charset=windows-874\n";
$emailMsg .= "Content-Transfer-Encoding: 8bit\n\n";
$emailMsg .= $_POST['fm_name'] . "\n";
$emailMsg .= $_POST['fm_email'] . "\n";
$emailMsg .= "--$boundary\n";
//echo $resume;
//echo $comment;
if($_FILES['Resume']['name'] != "")
{
$file_tmpname = $_FILES['Resume']['tmp_name'];
$file = fopen($file_tmpname,"rb");
$file_content = fread($file ,filesize($file_tmpname));
fclose($file);
$b64_enc = base64_encode($file_content) . "\n";
$file_split = chunk_split($b64_enc);
$mime_type = $_FILES['Resume']['type'];
$file_name = $_FILES['Resume']['name'];
//echo $file_tmpname;
$emailMsg .= "Content-Type: $mime_type; name=\"$file_name\"\n";
$emailMsg .= "Content-Transfer-Encoding: base64\n";
$emailMsg .= "Content-Disposition: attachment; filename=\"$file_name\"\n\n";
$emailMsg .= "$file_split\n";
$emailMsg .= "--$boundary--";
//echo $file_split;
}
if($_FILES['comment']['name'] != "")
{
$file_tmpname2 = $_FILES['comment']['tmp_name'];
$file2 = fopen($file_tmpname2,"rb");
$file_content2 = fread($file2 ,filesize($file_tmpname2));
fclose($file2);
$b64_enc2 = base64_encode($file_content2) . "\n";
$file_split2 = chunk_split($b64_enc2);
$mime_type2 = $_FILES['comment']['type'];
$file_name2 = $_FILES['comment']['name'];
//echo $file_tmpname2;
$emailMsg .= "Content-Type: $mime_type2; name=\"$file_name2\"\n";
$emailMsg .= "Content-Transfer-Encoding: base64\n";
$emailMsg .= "Content-Disposition: attachment; filename=\"$file_name2\"\n\n";
$emailMsg .= "$file_split2\n";
$emailMsg .= "--$boundary--";
//echo $file_split2;
}
//echo $emailMsg;
if (mail($emailTo, $emailSubject, $emailMsg, $emailHeader)) {
echo"<center><br> Send Complete </center>";
//echo "<meta http-equiv='refresh' content=2;URL=sendmail.php>";
}
else {
echo"<center><br> Send Fail </center>";
//echo "<meta http-equiv='refresh' content=2;URL=sendmail.php>";
}
}
?>
|
|
|
|
|
Date :
2009-11-10 11:49:29 |
By :
kasilot |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เทพ เทวดา ช่วยนู๋ด้วย เพี้ยงๆๆๆๆ TT-TT
|
|
|
|
|
Date :
2009-11-10 17:10:51 |
By :
kasilot |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมทดสอบแล้วมันก็ไปตามจำนวนที่เลือกน่ะครับ
|
|
|
|
|
Date :
2009-11-10 21:52:58 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ของดิฉัน มันแนบไปแค่ไฟล์เดียวอ่ะค่ะ
พอจะทราบมั้ยค่ะว่าเกิดจากอะไร
|
|
|
|
|
Date :
2009-11-11 09:08:09 |
By :
kasilot |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
บทความนี้น่ะครับ ได้แน่นอนครับ
Code (PHP Sending Email Multiple Array Upload Form & Attachment File)
<html>
<head>
<title>ThaiCreate.Com PHP Sending Email</title>
</head>
<body>
<form action="phpSendMailArrayUploadAttach.php" method="post" enctype="multipart/form-data" name="frmMain">
<table width="343" border="1">
<tr>
<td>To</td>
<td><input name="txtTo" type="text" ></td>
</tr>
<tr>
<td>Subject</td>
<td><input name="txtSubject" type="text"></td>
</tr>
<tr>
<td>Description</td>
<td><textarea name="txtDescription" cols="30" rows="4"></textarea></td>
</tr>
<tr>
<td>Form Name</td>
<td><input name="txtFormName" type="text"></td>
</tr>
<tr>
<tr>
<td>Form Email</td>
<td><input name="txtFormEmail" type="text"></td>
</tr>
<tr>
<td>Attachment</td>
<td>
<input name="fileAttach[]" type="file"><br>
<input name="fileAttach[]" type="file"><br>
<input name="fileAttach[]" type="file"><br>
<input name="fileAttach[]" type="file"><br>
<input name="fileAttach[]" type="file"><br>
<input name="fileAttach[]" type="file"><br></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Send"></td>
</tr>
</table>
</form>
</body>
</html>
|
|
|
|
|
Date :
2009-11-11 21:12:42 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองดูแล้วอ่าค่ะ แต่ไปแต่ไฟลืที่แนบไว้ตัวสุดท้ายอ่ะคะ
|
|
|
|
|
Date :
2009-11-12 10:06:52 |
By :
kasilot |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองสร้างไฟล์ใหม่แล้วทำตามบทความดูครับอย่าเพิ่งไปดัดแปลงอะไร
ทำในบทความดูก่อนว่า ได้ตามที่เพ่วินบอกหรือเปล่าครับ ถ้าได้แสดงว่าเรากำหนดอะไรผิดไปสักตัวหนึ่งนะครับ
ลองดูนะครับ สร้างไฟล์ใหม่เลยครับ
|
|
|
|
|
Date :
2009-11-12 10:22:46 |
By :
somparn |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองทำตามบทความแล้วค่ะ ไม่ได้ดัดแปลงสักกะตัวเดียว
แนบไป สามไฟล์ ผลลัพธ์คือ มาแค่ไฟล์ที่สามค่ะ
ไม่เข้าใจเหมือนกัน มันจะเกี่ยวกับ server อะไรหรือป่าวค่ะ
|
|
|
|
|
Date :
2009-11-12 13:31:31 |
By :
kasilot |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อ่ะ ตอนนี้แนบไฟล์ได้แล้วค่ะ แต่ไฟล์ที่มา เป็น (0.0 กิโลไบต์) อ่า งุงิ
|
|
|
|
|
Date :
2009-11-12 16:49:20 |
By :
kasilot |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<?
function verify_email($email){
list($email_user,$email_host)=explode("@",$email);
$host_ip=gethostbyname($email_host);
if(eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $email) && !ereg($host_ip,$email_host)) {
return true;
}else{
return false;
}
}
function msg($st){
print "
<form name='form1' method='post' action='javascript:history.back(1)'>
<table width='50%' border='1' align='center' cellpadding='0' cellspacing='0' bordercolor='#0000FF'>
<tr><td bgcolor='#0000FF'><font color='#FFFFFF'><b>ERROR</b></font><td>
</tr><tr>
<td><br><font color='red'><center>".$st."</center></font><br>
<div align='center'>
<input type='submit' name='submit' value=' OK '>
</div>
</td>
</tr></table></form>
";
exit();
}
if ((isset($_POST["sendmail"])) && ($_POST["sendmail"] == "form1")) {
$strTo= "[email protected]";
$strTo2= "[email protected]";
$sname=$_POST["sname"];
$subject=$_POST["subject"];
$message=$_POST["message"];
$frommail=$_POST["frommail"];
session_start();
if($_SESSION['captcha']!=$_POST['capt'] || $_SESSION['captcha']=='BADCODE') {
msg("You input code is wrong");
}
if ($sname==""){
msg("Please,Insert your name");
}
if ($subject==""){
msg("Please,Insert Subject");
}
if ($message==""){
msg("Please,Insert message");
}
if (verify_email($frommail)==false){
msg("E-mail incorrect");
}
require_once('class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsHTML(true); // กำหนดให้ ส่งเป็น html
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
// $mail->SMTPSecure = "ssl"; // sets the prefix to the servier
// $mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
// $mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Host = 'ssl://smtp.gmail.com:465'; // รวมเป็น ตัวแปลเดียว
$mail->Username = "[email protected]"; // GMAIL username หรือ domain ที่ใช้ระบบ Gmail ก็ได้
$mail->Password = "xxxxxxx"; // GMAIL password
$mail->From = $frommail; // เมลล์ผู้ส่ง
$mail->FromName = "คุณ ".$sname; // ชื่อผู้ส่ง
$mail->AddReplyTo($frommail,"คุณ ".$sname);
$mail->Subject = $subject;
$mail->Body = $message;
//$mail->AddAttachment($file_path);
$mail->AddAddress($strTo);// mail ผู้รับ
$mail->AddAddress($strTo2);// mail ผู้รับ 2
// Add Attachment 1
if (isset($_FILES['attachment1']))
{
if ($_FILES['attachment1']['size'] > "10485760")
{
msg("Attachment #1 is greater that 10M ");
}
if (strlen($msg) == 0)
{
$file1_path = $_FILES['attachment1']['tmp_name'];
$file1_name = $_FILES['attachment1']['name'];
$file1_type = $_FILES['attachment1']['type'];
$file1_error = $_FILES['attachment1']['error'];
$mail->AddAttachment($file1_path, $Subject . "_" . $file1_name); // optional name
}
}
// Add Attachment 2
if (isset($_FILES['attachment2']))
{
if ($_FILES['attachment2']['size'] > "10485760")
{
msg("Attachment #1 is greater that 10M ");
}
if (strlen($msg) == 0)
{
$file2_path = $_FILES['attachment2']['tmp_name'];
$file2_name = $_FILES['attachment2']['name'];
$file2_type = $_FILES['attachment2']['type'];
$file2_error = $_FILES['attachment2']['error'];
$mail->AddAttachment($file2_path, $Subject . "_" . $file2_name); // optional name
}
}
// Add Attachment 3
if (isset($_FILES['attachment3']))
{
if ($_FILES['attachment3']['size'] > "10485760")
{
msg("Attachment #1 is greater that 10M ");
}
if (strlen($msg) == 0)
{
$file3_path = $_FILES['attachment3']['tmp_name'];
$file3_name = $_FILES['attachment3']['name'];
$file3_type = $_FILES['attachment3']['type'];
$file3_error = $_FILES['attachment3']['error'];
$mail->AddAttachment($file3_path, $Subject . "_" . $file3_name); // optional name
}
}
$mail->Send(); // ส่ง
}
?>
ลองดูนะครับ
|
|
|
|
|
Date :
2010-01-10 19:32:56 |
By :
magicpc |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|