2013-04-02 4 views
0

PHP 메일 양식을 사용하고 있지만 양식 첨부 파일에 문제가 있습니다. 이 포럼을 검색하고 몇 가지 시도를했지만 작동하지 않았습니다. 아마 내 코드가 조금 다르기 때문일 것입니다. 내 양식이하는 일은 데이터베이스에 연결하고 작업 정보 (도시 제목)를 가져 와서 사용자가 그 정보를 입력하지 않아도됩니다 (일반적으로 어떻게 든 잘못 이해합니다). 누군가 내가 잘못하고있는 것을보기 위해 아래의 코드를 볼 수 있습니까? 오류가 없으며 메일이 전달되고 첨부되지 않습니다. 미리 감사드립니다.첨부 파일이 PHP 양식 메일러에 첨부되지 않음

$con = mysql_connect("connection") 

$id = $_GET['id']; 

if (isset($_POST["submit"])) { 
if($_POST || $_FILES) 

//if "email" is filled out, send email 
{ 
//send email 
$subject = $_POST['subject'] ; 
$title = $_POST['title'] ; 
$firstname = $_POST['firstname'] ; 
$middleinitial = $_POST['middleinitial'] ; 
$lastname = $_POST['lastname'] ; 
$email = $_POST['email'] ; 
$subject = $_POST['subject'] ; 
$city = $_POST['city'] ; 
$state = $_POST['state'] ; 
$phone = $_POST['phone'] ; 
$resume = $_POST['attachment'] ; 

$message = " 
Position Info 
-------------------------------- 
Title: $title 
Location: $city $state 

Applicant Info 
-------------------------------- 
First Name: $firstname 
Middle Initial: $middleinitial 
Last Name: $lastname 
E-mail: $email 
Phone: $phone"; 

// boundary 
$semi_rand = md5(time()); 
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 

// headers for attachment 
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; 

// multipart boundary 
$message = "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n"."Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; 
fixFilesArray($_FILES['attachment']); 
foreach ($_FILES['attachment'] as $position => $file) 
{ 
    // should output array with indices name, type, tmp_name, error, size 
    $message .= "--{$mime_boundary}\n"; 
    $fp  = @fopen($file['tmp_name'],"rb"); 
    $data = @fread($fp,filesize($file['tmp_name'])); 
    @fclose($fp); 
    $data = chunk_split(base64_encode($data)); 
    $message .= "Content-Type: application/octet-stream; name=\"".$file['name']."\"\n"."Content-Description: ".$file['name']."\n" ."Content-Disposition: attachment;\n" . " filename=\"".$file['name']."\";size=".$file['size'].";\n"."Content-Transfer-Encoding: base64\n\n" . $data . "\n\n"; 
} 
$message .= "--{$mime_boundary}--"; 
$returnpath = "-f" . $from; 
$ok = @mail($to, $subject, $message, $headers, $returnpath); 
if($ok){ return 1; } else { return 0; } 
} 
function fixFilesArray(&$files) 
{ 
$names = array('name' => 1, 'type' => 1, 'tmp_name' => 1, 'error' => 1, 'size' => 1); 

foreach ($files as $key => $part) { 
    // only deal with valid keys and multiple files 
    $key = (string) $key; 
    if (isset($names[$key]) && is_array($part)) { 
     foreach ($part as $position => $value) { 
      $files[$position][$key] = $value; 
     } 
     // remove old key reference 
     unset($files[$key]); 
    } 
} 
} 
} 

$sql = "select id,title,city,state from employment where id = $id"; 
$res = mysql_query($sql) or die('Could not display records'); 

if (mysql_num_rows($res) > 0) {  

echo '<form method="post" enctype="multipart/form-data" action="http://careers-admin.dbiservices.com/index.php?content=appform">'; 
echo '<input type="hidden" name="subject" value="Job Application">'; 
while ($row = mysql_fetch_assoc($res)) { 
echo '<table>'; 
echo '<tr><td align="right">'; 
    echo ' <b>Position Applying For</b></td><td> <input type="text" name="title" value="' . $row["title"] . '" size="30"> <br />' . "\n"; 
echo '<tr><td align="right">'; 
    echo ' <b>Location</b></td><td> <input type="text" name="city" value="' . $row["city"] . ' ' . $row["state"] .'" size="30"> <br />' . "\n"; 
echo '<tr><td align="right">'; 
    echo ' <b>First Name</b></td><td> <input type="text" name="firstname" size="30"> <br />' . "\n"; 
echo '<tr><td align="right">'; 
    echo ' <b>Middle Initial</b></td><td> <input type="text" name="middleinitial" size="5"> <br />' . "\n"; 
echo '<tr><td align="right">'; 
    echo ' <b>Last Name</b></td><td> <input type="text" name="lastname" size="30"> <br />' . "\n"; 
echo '<tr><td align="right">'; 
    echo ' <b>Email</b></td><td> <input type="text" name="email" size="30"> <br />' . "\n"; 
echo '<tr><td align="right">'; 
    echo ' <b>Phone</b></td><td> <input type="text" name="phone" size="30"> <br />' . "\n"; 
echo '<tr><td align="right">'; 
echo ' &nbsp;</td><td><em>In order to be considered for any open position, you<br> must attach a resume or type in a work history.</em> <br />' . "\n"; 
echo '<tr><td align="right">'; 
    echo ' <b>Resume</b></td><td> <input type="file" name="attachment[]" size="20" /> <br />' . "\n"; 
echo '</td></tr></table>'; 
} 
echo ' &nbsp; <input type="submit" name="submit" value="Submit Application">'; 
echo '</form>'; 
echo "<br><br><input type=button onClick=\"location.href='index.php'\" value='Back to Jobs'>"; 
} 



?> 
+0

'\ r \ n' 줄 끝 구분 기호를 사용해 보셨습니까? –

답변

0

move_uploaded_file 첫째, 당신은 그것을 당신을 사용해야하기 전에.

+0

바트 - 내 무지에 대해 사과드립니다. 나는 PHP에 매우 익숙하다. 정확히 'move_uploaded_file'을 먼저 움직여서 무엇을 의미하는지 확실히 모르겠다. – user2233638

+0

문서를 확인하십시오 : http://php.net/manual/en/function.move-uploaded-file.php –

관련 문제