|
|
|
ขอถามผู้รู้....การส่งไฟล์ PDF เข้า Email (มี Code ตัวอย่าง) |
|
|
|
|
|
|
|
อยากสอบถามการส่งไฟล์ PDF เข้า Email หน่อยค่ะ
พอดีเขียนโค๊ด แล้วมันส่งได้เกือบหมด "ยกเว้นตัวไฟล์ PDF ที่แนบอัพโหลด" ที่ไม่ถูกส่งมาด้วย
Code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
function onChange(val)
{
setOptions(val);
}
function onBegin(j)
{
var p = "<?php echo $_GET['p']; ?>";
setOptions(j);
var slBox= document.form1.slPosition;
for(var j=0;j<slBox.options.length;j++)
{
if(p==slBox.options[j].value)
{
slBox.options[j].setAttribute("selected", true);
}
}
}
function setOptions(chosen)
{
var slBox1= document.form1.slDepart;
var slBox= document.form1.slPosition;
slBox.options.length = 0;
if(chosen=="")
{
slBox.options[slBox.options.length] = new Option('Please select Position ','');
}
if(chosen=="Engineer")
{
slBox1.options[1].setAttribute("selected", true);
var states = new Array("","Cybersecurity Researcher","Cybersecurity Specialists","System Analyst", "System Design", "Project Manager","Team Leader","Senior Software Engineer","Software Engineer","Test Engineer","Technical Writer/Tester","Embedded Software Engineer","Electronic Design Engineer","UAV External Pilot","Senior Embedded Design Engineer","Embedded Design Engineer","Embedded technician Suport","Logistic Engineer","RF Communication Engineer","Telecommunication Engineer","Technical Support Engineer","Configuration Engineer","Configuration Management Officer","Document Control");
for(var i=0; i<states.length; i++)
{
if(i==0) { slBox.options[i] = new Option('Please select Position ',states[i]); }
else { slBox.options[i] = new Option(states[i],states[i]);}
}
}
if(chosen=="Management")
{
slBox1.options[2].setAttribute("selected", true);
var states = new Array("","Project Coordinator","Purchaser","Office Administrator","Assistant Administrator","Configuration Manager");
for(var i=0; i<states.length; i++)
{
if(i==0) { slBox.options[i] = new Option('Please select Position ',states[i]);}
else {slBox.options[i] = new Option(states[i],states[i]);}
}
}
if(chosen=="Accounting")
{
slBox1.options[3].setAttribute("selected", true);
slBox.options[slBox.options.length] = new Option('Accounting','Accounting');
}
if(chosen=="Others")
{
slBox1.options[4].setAttribute("selected", true);
var states = new Array("","Maintenance Staff");
for(var i=0; i<states.length; i++)
{
if(i==0) { slBox.options[i] = new Option('Please select Position ',states[i]);}
else {slBox.options[i] = new Option(states[i],states[i]);}
}
}
}
/* ------------------------------- end setOptions function -------------------------------*/
function checkValidate()
{
var slDepart=document.form1.slDepart;
var slPosition = document.form1.slPosition;
var txtName = document.form1.name;
var txtEmail = document.form1.email;
var txtTel1 = document.form1.tel1;
var txtTel2 = document.form1.tel2;
var txtUpload = document.form1.file;
var emailFormat=/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*\@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.([a-zA-Z]){2,4})$/;
var err = true;
if(slDepart.value==""&&slPosition.value ==""&&txtName.value ==""&&txtEmail.value==""&&txtTel1.value =="" && txtTel2.value ==""&&txtUpload.value==""){err=false; slDepart.focus();}
else if(slDepart.value==""){err=false; slDepart.focus(); }
else if(slPosition.value ==""){ err=false; slPosition.focus();}
else if(txtName.value ==""){ err=false; txtName.focus(); }
else if(!txtEmail.value.match(emailFormat)){ err=false; txtEmail.focus(); }
else if(txtTel1.value =="" && txtTel2.value ==""){ err=false; txtTel1.focus(); }
if(txtTel1.value !="")
{
if(isNaN(txtTel1.value)) {err=false; txtTel1.focus(); }
else if(txtTel1.value.substr(0,2) =='08' )
{
if( txtTel1.value.length<10){ err=false; txtTel1.focus(); }
}
else if(txtTel1.value.substr(0,2) =='02' )
{
if( txtTel1.value.length != 9){ err=false; txtTel1.focus(); }
}
else
{
err=false; txtTel1.focus();
}
}
if(txtTel2.value !="")
{
if(isNaN(txtTel2.value)) {err=false; txtTel2.focus(); }
else if(txtTel2.value.substr(0,2) =='08' )
{
if( txtTel2.value.length<10){ err=false; txtTel2.focus(); }
}
else if(txtTel2.value.substr(0,2) =='02' )
{
if( txtTel2.value.length != 9){ err=false; txtTel2.focus(); }
}
else
{
err=false; txtTel2.focus();
}
}
if(txtUpload.value==""){err=false; txtUpload.focus();}
else if(txtUpload.value.lastIndexOf('pdf')<=0){ err=false; txtUpload.focus();}
if(err==false) {alert('please check you information'); return false; }
else if(err==true){ delaypopup_open();return true;}
document.form1.submit();
}
function delaypopup_open(){
window.scrollTo(0,0);
document.getElementById('delay-popup').style.display='block';
document.getElementById('bg-popup').style.display='block';
}
</script>
</head>
<body>
<?
$num1 = rand(0,10);
$num2 = rand(0,10);
$_SESSION['total'] = ($num1 * $num2);
?>
<form id="form1" name="form1" method="post" enctype="multipart/form-data" action="careers-jobs_application-sendmail.php">
<table width="500" border="0" cellpadding="3" cellspacing="5">
<tr>
<td align="right">NAME :</td>
<td align="left"> <input type='text' name='name'></td>
</tr>
<tr>
<td align="right">EMAIL :</td>
<td align="left"> <input type='text' name='email'></td>
</tr>
<tr>
<td align="right">TELEPHONE 1 :</td>
<td align="left"> <input name='tel' type='text' maxlength="10"></td>
</tr>
<tr>
<td align="right">TELEPHONE 2 :</td>
<td align="left"> <input name='tel2' type='text' maxlength="10"></td>
</tr>
<tr>
<td width="35%" align="right">Department :</td>
<td colspan="2" align="left">
<select name="slDepart" id="slDepart" autofocus onchange="JavaScript: onChange(this.value);">
<option value="">Please select department</option>
<option value="Engineer">Engineer</option>
<option value="Management" >Management / Marketing</option>
<option value="Accounting">Accounting</option>
<option value="Others" >Others</option>
</select>
</td>
</tr>
<tr>
<td align="right">Position :</td>
<td colspan="2" align="left">
<select name="slPosition" id="slPosition" autofocus >
<option value="">Please select Position</option>
</select>
</td>
</tr>
<tr>
<td align="right">File Resume :</td>
<td width="42%" align="left"><input type="file" name="file" id="file" autocomplete="off" /></td>
</tr>
<tr>
<td align="right"> </td>
<td align="left">
<input type='hidden' name='action' value='1'>
<input type='submit' value=' SEND '>
</td>
</tr>
</table>
</form><br>
</body>
</html>
Code (PHP)
<?PHP
session_start();
/* Easy PHP Send mail by mean (http://oldirh.com)
# Create : 22/06/2009
*/
if($_POST['action']){
if($_POST['verifycode'] !=$_SESSION['total'] ){
echo " Verify Code ไม่ถูกต้อง โปรดใสใหม่อีกครั้ง<br>";
}else{
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$headers .= "From: ".$_POST['name']." <".$_POST['email'].">\r\n";
$msgs .= " <h2><strong>This job is automatically sent from job application form at gruopavia </strong></h2> ";
$msgs .= " <strong>NAME :</strong> ".$_POST['name'].'<br>';
$msgs .= " <strong>EMAIL : </strong> ".$_POST['email'].'<br>';
$msgs .= " <strong>TELEPHONE1 : </strong> ".$_POST['tel'].'<br>';
$msgs .= " <strong>TELEPHONE2 : </strong> ".$_POST['tel2'].'<br><hr>';
$msgs .= " <strong>DEPARTMENT : </strong> ".$_POST['slDepart'].'<br>';
$msgs .= " <strong>POSITION : </strong> ".$_POST['slPosition'].'<br>';
$strFilesName = $_FILES["file"]["name"];
$handle=fopen($_FILES["file"]["tmp_name"],'rb');
$content=fread($handle,$_FILES["file"]["size"]);
fclose($handle);
$strContent = chunk_split(base64_encode($content));
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-Type: application/pdf; name=\"".$strFilesName."\"\n";
$strHeader .= "Content-Transfer-Encoding: base64\n";
$strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
$strHeader .= $strContent."\n\n";
$subapply = "Job Apply GroupAvia";
$mailto = "[email protected]"; # อีเมล์ผู้รับ
if(mail($mailto, $subapply, $msgs, $headers, $strFilesName)){
echo "<script> alert('Your job is sent to successfully.'); window.location = 'careers-jobs_application.php'; </script>"; //ย้ายไปหน้า contact-avia2.php
}else{
echo "no send";
}
exit();
}
}
?>
Tag : PHP, HTML/CSS, JavaScript, CakePHP, Windows, Web Hosting
|
|
|
|
|
|
Date :
2016-06-03 14:35:36 |
By :
itengineer |
View :
1341 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ถ้าจะแนบไฟล์ ลองเปลี่ยนไปใช้พวก Library นะครับ จัดการง่ายกกว่ามาก
Code (PHP)
<?php
require_once("mimemail.inc.php");
$mail = new MIMEMAIL("HTML"); // HTML Format
$mail->senderName = "sender name";
$mail->senderMail = "sender@email";
$mail->cc = "cc@email";
$mail->bcc = "bcc@email";
$mail->subject = "This is the subject line";
$mail->body = "Hello! This is a message for you."; // OR: $mail->body = "path_to_file/filename";
$mail->attachment[] = "path_to_file1/filename1";
$mail->attachment[] = "path_to_file2/filename2";
$mail->create();
$mail->send("recipient1@email");
$mail->send("recipient2@email,recipient3@email,recipient4@email");
?>
PHP Mail Class (MIMEMAIL V 1.5)
|
|
|
|
|
Date :
2016-06-03 16:49:48 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|