2014-09-04 146 views
0
<?php 
include_once('admin/dbcon.php'); 
if(isset($_POST["submit"])=="Apply Now") 
{ 
    //$resume=''; 
    //$photos=''; 
    $fullname = strip_tags($_POST["fullname"]); 
    $address = strip_tags($_POST["address"]); 
    $state = strip_tags($_POST["state"]); 
    $city = strip_tags($_POST["city"]); 
    $mobile = strip_tags($_POST["mobile"]); 
    $email = strip_tags($_POST["email"]); 
    $username="xxxxxxx"; 
    $apply_for = strip_tags($_POST["apply_for"]); 
    /*Resume file uploaded*/ 
     $allowedExts = array("pdf", "doc", "docx"); 
     $extension = end(explode(".", $_FILES["up_resume"]["name"])); 
     if ($_FILES["up_resume"]["type"] == "application/pdf" || 
      $_FILES["up_resume"]["type"] == "application/msword" || 
      $_FILES["up_resume"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document") 
     {  
     $type =substr($_FILES["up_resume"]["name"],strrpos($_FILES["up_resume"]["name"], '.') + 1); 
     $resume = "Resume_".time().".".$type; 

     move_uploaded_file($_FILES["up_resume"]["tmp_name"], "admin/upload/".$resume); 
     } 
     else 
     { 
     header("Location:apply-now.php?rm=Invalid file, Please upload your updated resume!!"); 
     }  
    /*Photo uploaded here*/ 
     $allowedExts1 = array("gif", "jpeg", "jpg", "png"); 
     $extension1 = end(explode(".", $_FILES["profiel_photos"]["name"])); 
     if ($_FILES["profiel_photos"]["type"] == "image/gif" || $_FILES["profiel_photos"]["type"] == "image/jpeg" || 
      $_FILES["profiel_photos"]["type"] == "image/pjpeg" || $_FILES["profiel_photos"]["type"] == "image/png" || $_FILES["profiel_photos"]["type"] == "image/jpg") 
     {  
     $type1 =substr($_FILES["profiel_photos"]["name"],strrpos($_FILES["profiel_photos"]["name"], '.') + 1); 
     $photos = "prf_img_".time().".".$type1; 

     move_uploaded_file($_FILES["profiel_photos"]["tmp_name"], "admin/upload/".$photos); 
     } 
     else 
     { 
     header("Location:apply-now.php?pic=Invalid file,Please upload your updated photos!!"); 
     } 
    $status = "INSERT INTO `caretel`.`tb_career` (`FullName`, `Address`, `State`, `City`, `ContactNo`, `Email`, `Resume`, `ProfileImg`, `ApplyFor`) VALUES ('$fullname', '$address', '$state', '$city', '$mobile', '$email', '$resume', '$photos', '$apply_for')"; 
    if(mysql_query($status)) 
    { 
    require_once('include/class.phpmailer.php'); 
    $mail = new PHPMailer(); 
     $mail->IsSMTP(); // 
     $mail->Host  = "smtp.gmail.com"; 
     $mail->SMTPDebug = 1;      
     $mail->SMTPAuth = true;     
     $mail->Host  = "smtp.gmail.com"; 
     $mail->Port  = 25;      
     $mail->Username = "[email protected]"; 
     $mail->Password = "XXXXXXX";   
     //$mail->SMTPSecure = "ssl"; 
     $mail->SMTPSecure = "tls"; 

     $mail->AddAddress($email,"Guest"); 
     $mail->SetFrom("[email protected]","XXXXXXXX"); 
     $mail->Subject = "New Applicat Applyed for ".$apply_for; 

     $body = 'html'; 

    $mail->MsgHTML($body); 
    $mail->AddAttachment("admin/upload/".$resume);  // attachment 
    $mail->AddAttachment("admin/upload/".$photos); // attachment 

    if($mail->Send()) 
    { 
     echo "hi"; 
     header("Location:apply-now.php?msg=Thank you for Apply. We will be in touch with you very soon!!"); 

     exit; 

    }else{ 

     header("Location:apply-now.php?msg=We encountered an error sending your mail"); 

     exit; 
     }  
    } 
}else{ 
echo "dfsdfsdfsdf "; 
} 

?> 

郵件不發送,而不是重定向到應用,now.php頁我也我們端口使用SSL 465和TLS 587和不顯示郵件發送只能重定向後的任何類型的錯誤在我的動作php頁面上,這個代碼有什麼問題請幫助我 謝謝失敗郵件發送後重定向,而不是發送郵件

+0

負載PHPMailer的。要診斷這一點,請在使用重定向之前對發送進行整理 - 它們會阻止您看到調試輸出。對於gmail,你肯定應該在587上使用tls。如果你打算使用調試輸出,我建議你設置'$ mail-> SMTPDebug = 3;'來更全面地瞭解發生了什麼。 – Synchro 2014-09-04 06:57:03

+0

您應該將腳本分解爲多個部分並獨立測試(函數或類)。例如用虛擬數據測試郵件程序。自己測試重定向。測試表單提交沒有附件,最後一切都在一起。我建議使用像Symfony2 \ HttpFoundation這樣的庫來處理請求和重定向,並使用SwiftMailer發送電子郵件。這些庫很好地維護和記錄。最後,使用參數化查詢將數據寫入數據庫,您目前正在執行的方式將允許任何人執行SQL注入攻擊。 – Onema 2014-09-04 06:59:24

回答

0

在發送之前,我們必須修改PHPMailer對象以表明消息應該被解釋爲HTML。從技術上講,消息體必須設置爲多部分/備選。這是通過:

$ mail-> IsHTML(true);

欲瞭解更多信息,您可以通過加載它自動加載,而不是類(並確保您正在使用最新版本)visit here

+0

不需要:'msgHTML()'爲你設置。 – Synchro 2014-09-04 06:53:17