2016-06-28 2 views
1

업로드 버튼과 사용자의 세부 정보가있는 html로 양식을 만들고 있습니다. 양식의 모든 세부 정보를 사용자가 업로드 한 파일과 함께 보내고 싶습니다. 하지만 그것은 작동하지 않습니다. 나는 내 HTML 코드와 PHP 코드의 코드도 게시하고 있습니다. 내가 어디에서 실종되었는지 말해.첨부 파일이 php의 메일에 들어 가지 않습니다

<!DOCTYPE html> 
<html> 
<head> 

<link rel="stylesheet" type="text/css" href="style.css" /> 

<body> 


    <div class="element"> 
     <a href="index.php"><img src="logo.gif"></a> 
      <br><br> 
    <div class="new"></div> 
    <center><h2>Submit Your Information below</h2></center> 

    <form name="registration" method="post" action="fromaction.php" enctype="mutipart/form-data" autocomplete="off"> 
     <!-- <span class="erorr"> ---> 
     <div class="image"></div> 
     <label>Name:</label> 
     <input id="box1" placeholder="Type here" type="text" name="Name:" required> 
     <br><br> 

    <label>Email:</label><input id="box2" placeholder="Type here" type="email" name="Email:" required > 
     <br> 
     <br> 

    <label>Time period in which you will join</label> 
      <select id ="myList" name="Time Required by user to Join the company" > 
       <option value="Immediate" required>Immediate</option> 
       <option value="Less than one month">Less than one month</option> 
       <option value="1 month">1 month</option> 
       <option value="2 months">2 months</option> 
      </select> 

     <br><br> 

    <label>Linkedin Link:</label> 
     <input type="text" id="box3" name="Linkedin ID" placeholder="https://www" required > 
     <br><br> 

     <label for="workexcel">What job responsibilities and duties do you excel at?</label> 

     <textarea name="At which The User is Excel in:" placeholder="Type Here.." id="add" rows="2" cols="2" maxlength="300" required></textarea> 

     <br><br> 

     <label>Tell me about a challenge or conflict you've faced at work, and how you dealt with it.</label> 

      <textarea name="How user dealt with challenge or conflict" placeholder="Type Here.." rows="2" cols="2" maxlength="300" required ></textarea>   
     <br><br> 


      <label for"twork">What is your greatest professional achievement?</label> 

       <textarea name="User Professional achievement:" placeholder="Type here.." id="twork" rows="10" cols="30" maxlength="300" required></textarea> 
       <br> 

        <br><br> 

     <label for="det">Tell us something about Yourself</label>&nbsp;&nbsp; 

     <textarea name= "Details About the user" placeholder="Type here.." id="det" rows="10" cols="30" maxlength="300" required ></textarea> 

      <br><br> 

     <label for="resume">Attach Your Resume here </label> 

     <input type="file" name="uploaded_file"> 
     <br><br> 


     <input type="checkbox" value="Area" required>&nbsp;&nbsp;I understand that I am applying for the job which is of my Area of field. 
     <br> 
     <h1><input id="submit" type="Submit" value="Submit"></h1> 


     <!-- </span> --> 
    </form>  


    </div> 
    </body> 
    </head> 
    </html> 

PHP 코드는 여기

<?php 

    $c_name=$_POST['Name:']; // Contain Candidate name 
    $c_email=$_POST['Email:']; // Contain email 
    $c_time=$_POST['Time Required by user to Join the company']; 
    $c_linkedin=$_POST['Linkedin ID']; 
    $c_Excel=$_POST['At which The User is Excel in:']; 
    $c_challenge=$_POST['How user dealt with challenge or conflict']; 
    $c_professional=$_POST['User Professional achievement:']; 
    $c_details=$_POST['Details About the user']; 

    $file_name=$_FILES['uploaded_file']['name']; 
    $temp_name=$_FILES['uploaded_file']['tmp_name']; 
    $file_type=$_FILES['uploaded_file']['type']; 

    //get the extension of the file 
    $base = basename($file_name); 
    $extension=substr($base, strlen($base)-4,strlen($base)); 
    $allowed_extensions=array(".doc","docx",".pdf",".zip",".png"); 

    if(in_array($extension,$allowed_extensions)){ 

     $from = $_POST['Email:']; 
     $to = "[email protected]"; 
     $subject = "testing"; 

     $message = "<table width='800' border='1' cellspacing='0' cellpadding='8' bordercolor='#CCCCC'>  
     <tr>   
       <td colspan='2' bgcolor='#CDD9F5'><strong>Candidate Details</strong></td>    
     </tr> 
     <tr>   
      <td width='168' bgcolor='#FFFFEC'><strong>Candidate Name</strong></td>   
      <td width='290' bgcolor='#FFFFEC'>$c_name</td>  
     </tr>  
     <tr>   
      <td bgcolor='#FFFFDD'><strong>E-mail ID</strong></td>   
      <td bgcolor='#FFFFDD'>$c_email</td>  
     </tr> 
     <tr>   
      <td bgcolor='#FFFFDD'><strong>Time required by user to Join the Company</strong></td>   
      <td bgcolor='#FFFFDD'>$c_time</td>  
     </tr>       
     <tr>   
      <td bgcolor='#FFFFDD'><strong>Linkedin ID</strong></td>   
      <td bgcolor='#FFFFDD'>$c_linkedin</td>  
     </tr>       
     <tr>   
      <td bgcolor='#FFFFDD'><strong>Excel</strong></td>   
      <td bgcolor='#FFFFDD'>$c_Excel</td> 
     </tr>       
      <tr>   
      <td bgcolor='#FFFFDD'><strong>challenge</strong></td>   
      <td bgcolor='#FFFFDD'>$c_challenege</td>  
     </tr>      
     <tr>   
      <td bgcolor='#FFFFDD'><strong>professional</strong></td>   
      <td bgcolor='#FFFFDD'>$c_professional</td> 
     </tr>       
     <tr>   
      <td bgcolor='#FFFFDD'><strong>details</strong></td>   
      <td bgcolor='#FFFFDD'>$c_details</td>  
     </tr>       
    </table>"; 

     $file=$temp_name; 
     $content = chunk_split(base64_encode(file_get_contents($file))); 
     $uid=md5(uniqid(time())); 

     $header= "From: ".$from."\r\n"; 
     $header.= "reply to:" .$replyto."\r\n"; 
     $header.= "MIME-Version: 1.0\r\n"; 

     $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; 
     $header .="this is multipart mesage in MIME format.\r\n"; 
     $header .= "--".$uid."\r\n"; 
     $header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; 
     $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; 
     $header .= $message."\r\n\r\n"; 

     $header .= "--".$uid."\r\n"; 
     $header .= "Content-type:".$file_type."; name=\"".$file_name."\"\r\n"; 
     $header .= "Content-Transfer-Encoding: base64\r\n"; 
     $header .= "Content-Disposition: attachment; filename=\"".$file_name."\"\r\n\r\n"; 

     $header .= $content."\r\n\r\n"; 

     if(mail($to, $subject, "", $header)){ 
      echo "success"; 
     }else{ 
      echo"fail"; 
     } 

    }else{ 
     echo "file type not allowed"; 
    } 
?> 

답변

0

는 PHP를 사용하여 이메일을 보낼 수있는 더 좋은 방법이있다. 나는 phpMailer를 사용 해보길 권합니다. 당신은 그것을 here 얻을 수 있습니다. phpMailer은 매우 좋은이며, 당신은 단지 phpmailer 클래스를 다운로드하고 require_once('includes/php_mailer/class.phpmailer.php');이 코드에 포함이 기능

function send_mail_with_attachment($upload_path,$from_name,$from_mail,$replyto,$to,$message,$filenames,$subject) { 


$mail = new PHPMailer; 

//$mail->SMTPDebug = 3;        // Enable verbose debug output 

$mail->setFrom($from_mail, $from_name); 
$mail->addAddress($to);  // Add a recipient 

$mail->addBCC('[email protected]'); 
$mail->addBCC('[email protected]'); 
$mail->addAttachment($upload_path.$filenames);   // Add attachments 
    // Optional name 
$mail->isHTML(true);         // Set email format to HTML 

$mail->Subject = $subject; 
$mail->Body = $message; 
$mail->AltBody = $message; 

if(!$mail->send()) { 

    echo 'Message could not be sent.'; 
    echo 'Mailer Error: ' . $mail->ErrorInfo; 
} else { 
    echo 'success'; 
} 




    } 

와 함께 phpmailer 클래스를 사용할 수 있습니다 아주 잘

+0

당신은 Gmail을 사용하고 있습니까? Gmail에는 외부에서 데이터를 제한하는 보안 조치가 있습니다. 외부에서받은 데이터를 받아들이도록 gmail 계정의 설정을 변경해야합니다 – theTypan

+0

gmail에서 어떤 변경 사항을 변경해야합니까? 여기에 대한 힌트가 있습니까? – Abhinav

+0

덜 안전한 앱의 설정을 변경합니다. 희망이 [link] (https://support.google.com/accounts/answer/6010255?hl=ko) 변경에 도움이 될 것입니다 – theTypan

1

첨부 파일을 처리합니다. 나는 그것이 당신을 위해 일할 것이라는 점을 희망한다

+0

코드가 작동하지 않습니다 – Abhinav

+0

먼저 smtp 구성을 확인하십시오 –

+0

@Abhinav firt simple 보내기 일반 이메일 thrugh PHP 코드 및 귀하의 이메일 보내기 서버 즉, smtp 서버가 올바르게 구성되어 있는지 테스트 –

0

이것을 잘 시도해보십시오! SMTP 코드

<div class="element"> 
    <a href="http://tenmiles.com/index.php"><img src="logo.gif"></a> 
     <br><br> 
<div class="new"></div> 
<center><h2>Submit Your Information below</h2></center> 

<form action="1.php" method="post" enctype="multipart/form-data" autocomplete="off"> 
    <!-- <span class="erorr"> ---> 
    <div class="image"></div> 
    <label>Name:</label> 
    <input id="box1" placeholder="Type here" type="text" name="Name" required> 
    <br><br> 

<label>Email:</label><input id="box2" placeholder="Type here" type="email" name="Email" required > 
    <br> 
    <br> 

<label>Time period in which you will join</label> 
     <select id ="myList" name="Time" > 
      <option value="Immediate" required>Immediate</option> 
      <option value="Less than one month">Less than one month</option> 
      <option value="1 month">1 month</option> 
      <option value="2 months">2 months</option> 
     </select> 

    <br><br> 

<label>Linkedin Link:</label> 
    <input type="text" id="box3" name="Linkedin_ID" placeholder="https://www" required > 
    <br><br> 

    <label for="workexcel">What job responsibilities and duties do you excel at?</label> 

    <textarea name="excel" placeholder="Type Here.." id="add" rows="2" cols="2" maxlength="300" required></textarea> 

    <br><br> 

    <label>Tell me about a challenge or conflict you've faced at work, and how you dealt with it.</label> 

     <textarea name="conflict" placeholder="Type Here.." rows="2" cols="2" maxlength="300" required ></textarea>   
    <br><br> 


     <label for"twork">What is your greatest professional achievement?</label> 

      <textarea name="Professional" placeholder="Type here.." id="twork" rows="10" cols="30" maxlength="300" required></textarea> 
      <br> 

       <br><br> 

    <label for="det">Tell us something about Yourself</label>&nbsp;&nbsp; 

    <textarea name= "About" placeholder="Type here.." id="det" rows="10" cols="30" maxlength="300" required ></textarea> 

     <br><br> 

    <label for="resume">Attach Your Resume here </label> 

    <input type="file" name="smtpimg"> 
    <br><br> 


    <input type="checkbox" value="Area" required>&nbsp;&nbsp;I understand that I am applying for the job which is of my Area of field. 
    <br> 
    <h1><input id="submit" type="Submit" name="submit" value="Submit"></h1> 


    <!-- </span> --> 
</form>  


</div> 
</body> 
</head> 
</html> 

당신의 PHP 여기

<?php 
include "PHPMailer_5.2.4/class.phpmailer.php"; 
if(isset($_POST["submit"])){ 
       // $email = $_POST["emailfrom"]; 
       $target_dir = "smtpimg/"; 
$target_file= $target_dir .time().basename($_FILES['smtpimg']['name']); 
$movefile=move_uploaded_file($_FILES['smtpimg']['tmp_name'], $target_file); 
$message = "<table width='800' border='1' cellspacing='0' cellpadding='8' bordercolor='#CCCCC'>  
     <tr>   
       <td colspan='2' bgcolor='#CDD9F5'><strong>Candidate Details</strong></td>    
     </tr> 
     <tr>   
      <td width='168' bgcolor='#FFFFEC'><strong>Candidate Name</strong></td>   
      <td width='290' bgcolor='#FFFFEC'>'".$_POST['Name']."'</td>  
     </tr>  
     <tr>   
      <td bgcolor='#FFFFDD'><strong>E-mail ID</strong></td>   
      <td bgcolor='#FFFFDD'>'".$_POST['Name']."'</td>  
     </tr> 
     <tr>   
      <td bgcolor='#FFFFDD'><strong>Time required by user to Join the Company</strong></td>   
      <td bgcolor='#FFFFDD'>'".$_POST['Email']."'</td>  
     </tr>       
     <tr>   
      <td bgcolor='#FFFFDD'><strong>Linkedin ID</strong></td>   
      <td bgcolor='#FFFFDD'>'".$_POST['Linkedin_ID']."'</td>  
     </tr>       
     <tr>   
      <td bgcolor='#FFFFDD'><strong>Excel</strong></td>   
      <td bgcolor='#FFFFDD'>'".$_POST['excel']."'</td> 
     </tr>       
      <tr>   
      <td bgcolor='#FFFFDD'><strong>challenge</strong></td>   
      <td bgcolor='#FFFFDD'>'".$_POST['conflict']."'</td>  
     </tr>      
     <tr>   
      <td bgcolor='#FFFFDD'><strong>professional</strong></td>   
      <td bgcolor='#FFFFDD'>'".$_POST['Professional']."'</td> 
     </tr>       
     <tr>   
      <td bgcolor='#FFFFDD'><strong>details</strong></td>   
      <td bgcolor='#FFFFDD'>'".$_POST['About']."'</td>  
     </tr>       
    </table>"; 
    print_r($message); 
$mail = new PHPMailer(); 

$mail->IsSMTP(); 
$mail->SMTPDebug = 1; 
$mail->SMTPAuth = true; 
$mail->SMTPSecure = 'ssl'; 
$mail->Host = "smtp.gmail.com"; 

$mail->Port = 465; 
$mail->IsHTML(true); 
$mail->Username = "[email protected]"; 
$mail->Password = "yourgmailpassword"; 
$mail->AddReplyTo("[email protected]", "Reply name"); 
$mail->AddAddress($_POST['Email'],'ashu'); 
$mail->Subject = "SMTP Receivced"; 
$mail->Body = "<b>Succesfully SMTP Receivced</b>"; 
$mail->AddAttachment($target_file); 
$mail->MsgHTML($message); 
$text = 'Text version of email'; 
$html = '<html><body>HTML version of email</body></html>'; 
$file = 'index.php'; 
$crlf = "\n"; 
$hdrs = array(
       'From' => '[email protected]', 
       'Subject' => 'Test mime message' 
      ); 
if($mail->send($hdrs)) 
{ 
echo "<script> alert('Successfully Mailed');window.location = 'pra-2.php';</script>"; 
} 
else{ 
echo "Mailed Error: " . $mail->ErrorInfo; 
} 
} 
?> 

enter image description here

+0

에서 다운로드 할 수 있습니다. php mailer를 다운로드하려면 https://sourceforge.net/projects/phpmailer/ –

+0

안녕하세요, 지금 내 메일에 파일이 있지만 첨부 파일이 누락되었습니다.이 코드를 사용했습니다. 첨부 '$ 메일 -> AddAttachment ($ _ FILES는 ['uploaded_file '] ['tmp_name '], $는 _ FILES는 ['uploaded_file는 '] ['이름 ']); 코드 위' – Abhinav

+0

는 화면을 참조 #abhinav 완벽 shot –

관련 문제