php发送带有PDF附件的电子邮件不';t发送

php发送带有PDF附件的电子邮件不';t发送,php,email,pdf,Php,Email,Pdf,我正在创建pdf并将其发送到电子邮件id。我做了所有事情,但邮件未发送到邮件id。页面(apply_online_form.php)显示为空,如下所示 这是我的代码,如何解决此错误。。?提前谢谢 apply\u online\u form.php <?php if($_POST['id_email'] == '') { header('Location: applynow.php?failure'); } else { require('admin/fpdf.php');

我正在创建pdf并将其发送到电子邮件id。我做了所有事情,但邮件未发送到邮件id。页面(apply_online_form.php)显示为空,如下所示

这是我的代码,如何解决此错误。。?提前谢谢

apply\u online\u form.php

<?php

if($_POST['id_email'] == '') {
    header('Location: applynow.php?failure');
}
else {

require('admin/fpdf.php');

class PDF extends FPDF
{
    // Page header
    function Header()
    {
        // Logo
        $this->Image('admin/logo.png',10,6,30);
        // Arial bold 15
        $this->SetFont('Arial','B',15);
        // Move to the right
        $this->Cell(80);
        // Title
        $this->Cell(50,10,'Job Application',1,0,'C');
        // Line break
        $this->Ln(20);
    }

    // Page footer
    function Footer()
    {
        // Position at 1.5 cm from bottom
        $this->SetY(-15);
        // Arial italic 8
        $this->SetFont('Arial','I',8);
        // Page number
        $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
    }
}

function mail_attachment ($to, $subject, $message, $attachment){
    $from = 'abc@domain.com';#
    $fileatt = $attachment; // Path to the file
    $fileatt_type = "application/octet-stream"; // File Type

    $start = strrpos($attachment, '/') == -1 ?
    strrpos($attachment, '//') : strrpos($attachment, '/')+1;

    $fileatt_name = substr($attachment, $start, strlen($attachment)); 

    $email_from = $from; // Who the email is from
    //$subject = "New Attachment Message";

    $email_subject =  $subject; // The Subject of the email
    $email_txt = $message; // Message that the email has in it
    #$email_to = $to; // Who the email is to
    $email_to = $_POST['id_email'];

    $headers = "From: abc@domain.com";
    $file = fopen($fileatt,'rb');
    $data = fread($file,filesize($fileatt));
    fclose($file);

    $msg_txt="\n\n You have recieved a new attachment message from $from";
    $semi_rand = md5(time());
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
    $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . "
            boundary=\"{$mime_boundary}\"";

    $email_txt .= $msg_txt;

    $email_message = "This is a multi-part message in MIME format.\n\n" .
            "--{$mime_boundary}\n" . "Content-Type:text/html;
            charset = \"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" .
            $email_txt . "\n\n";

        $data = chunk_split(base64_encode($data));

    $ok = mail($email_to, $email_subject, $email_message, $headers);

        if($ok) {
            echo "File Sent Successfully.";
            unlink($attachment); // delete a file after attachment sent.
        }else {
            die("Sorry but the email could not be sent. Please go back and try again!");
        }   
    }

        $title= $_POST['id_title'];
        $first_name = $_POST['id_first_name'];
        $last_name= $_POST['id_last_name'];
            $dob = $_POST['id_checkin'];
        $slide= (isset($_POST['id_slide'])) ? $_POST['id_slide'] : 0;
        $hear= $_POST['txt_hear'];
        $refer= $_POST['txt_refer'];
        $salary= $_POST['txt_salary'];
        $exp_sal= $_POST['txt_exp_sal'];
        $notice= $_POST['txt_notice'];
        $exp= $_POST['txt_exp'];
        $txt_desgination= $_POST['txt_design'];
        $blood= $_POST['txt_blood'];
        $email= $_POST['id_email'];
        $phone= $_POST['id_phone'];
        $address = $_POST['id_address'];

        $degree= $_POST['txt_degree'];
            $school = $_POST['txt_school'];
        $year= $_POST['txt_year'];
        $marks= $_POST['txt_marks'];

        $scholarship= $_POST['txt_scholarship'];
        $training= $_POST['txt_training'];

        $langg= $_POST['txt_langg'];
        $speak= (isset($_POST['speakk'])) ? $_POST['speakk'] : '';
        $read= (isset($_POST['read'])) ? $_POST['read'] : '';
        $write= (isset($_POST['write'])) ? $_POST['write'] : '';

        $companynane= $_POST['txt_companyname'];
        $position= $_POST['txt_position'];
        $comp= $_POST['txt_comp'];
        $super= $_POST['txt_super'];
        $period= $_POST['txt_period'];
        $salary= $_POST['txt_salary'];
        $job_desc= $_POST['txt_job_desc'];
        $emp= $_POST['txt_emp'];

        $members= $_POST['txt_members'];
        $accident= $_POST['txt_accident'];
        $litigation= $_POST['txt_litigation'];

        $ref_name= $_POST['pro_ref_name'];
        $ref_add= $_POST['pro_ref_add'];
        $ref_how= $_POST['pro_ref_how'];

        /*$date=date('d-M-Y');
        $datee=date('Y-m-d');*/

         //$to = $email;
     $to = "tomail@gmail.com";
     $to_mail="webenquiry@forceindiapharma.com";
         $subject = "Contact Us";
         $subject2 = "Copy of your form submission";
         $headers = 'MIME-Version: 1.0' . "\r\n";
         $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
         $headers .= "From: webenquiry@forceindiapharma.com ";

        $pdf = new PDF();
    $pdf->AliasNbPages();
    $pdf->AddPage();
    $pdf->SetFont('Times','',12);

    $pdf->Cell(90,7,'Name',0,0,'L');
    $pdf->Cell(100,7, $title.' '.$first_name.' '.$last_name,0,0,'L');
    $pdf->Ln();
    $pdf->Cell(90,7,'Date of Birth',0,0,'L');
    $pdf->Cell(100,7, $dob,0,0,'L');
    $pdf->Ln();
    $pdf->Cell(90,7,'Marital Status',0,0,'L');
    $maritalStatus = ($slide == 1) ? 'Yes': 'No';
    $pdf->Cell(100,7, $maritalStatus,0,0,'L');
    $pdf->Ln();
    $pdf->Cell(90,7,'How did you hear about us?',0,0,'L');
    $pdf->Cell(100,7, $hear,0,0,'L');
    $pdf->Ln();
    $pdf->Cell(90,7,'Reference',0,0,'L');
    $pdf->Cell(100,7, $refer,0,0,'L');
    $pdf->Ln();
    $pdf->Cell(90,7,'Current Salary',0,0,'L');
    $pdf->Cell(100,7, $salary,0,0,'L');
    $pdf->Ln();
    $pdf->Cell(90,7,'Expected Salary',0,0,'L');
    $pdf->Cell(100,7, $exp_sal,0,0,'L');
    $pdf->Ln();
    $pdf->Cell(90,7,'Notice Period',0,0,'L');
    $pdf->Cell(100,7, $notice,0,0,'L');
    $pdf->Ln();
    $pdf->Cell(90,7,'Total Experience',0,0,'L');
    $pdf->Cell(100,7, $exp,0,0,'L');
    $pdf->Ln();
    $pdf->Cell(90,7,'Current Designation',0,0,'L');
    $pdf->Cell(100,7, $txt_desgination,0,0,'L');
    $pdf->Ln();
    $pdf->Cell(90,7,'Blood Group',0,0,'L');
    $pdf->Cell(100,7, $blood,0,0,'L');
    $pdf->Ln();
    $pdf->Cell(90,7,'Email',0,0,'L');
    $pdf->Cell(100,7, $email,0,0,'L');
    $pdf->Ln();
    $pdf->Cell(90,7,'Phone',0,0,'L');
    $pdf->Cell(100,7, $phone,0,0,'L');
    $pdf->Ln();
    $pdf->Cell(90,7,'Address',0,0,'L');
    $pdf->MultiCell(100,10, $address);
    $pdf->Ln();
    $pdf->Cell(0,7,'Qualifications (S S C ONWARDS)',0,0,'C');
    $pdf->Ln();
    $pdf->Cell(40,7,'Degree / Diploma',1,0,'C');
    $pdf->Cell(80,7, 'School / College / University',1,0,'C');
    $pdf->Cell(30,7,'Year of Passing',1,0,'C');
    $pdf->Cell(40,7, '% of mark',1,0,'C');
    $pdf->Ln();
    for($i = 0; $i < count(array_filter($_POST['txt_langg'])); $i++) {
        $pdf->Cell(40,7,$_POST['txt_degree'][$i],1,0,'L');
        $pdf->Cell(80,7, $_POST['txt_school'][$i],1,0,'L');
        $pdf->Cell(30,7,$_POST['txt_year'][$i],1,0,'L');
        $pdf->Cell(40,7,$_POST['txt_marks'][$i],1,0,'L');
        $pdf->Ln();
    }
    $pdf->Ln();
    $pdf->Cell(0,7,'OTHER ACHIEVEMENTS (Scholarships / Prizes Won, Papers Published / Professional Approvals)',0,0,'L');
    $pdf->Ln();
    $pdf->MultiCell(0,10, $_POST['txt_scholarship']);
    $pdf->Ln();
    $pdf->Cell(0,7,'Special Training Received / Project Work Done',0,0,'L');
    $pdf->Ln();
    $pdf->MultiCell(0,10, $_POST['txt_training']);
    $pdf->Ln();
    $pdf->Cell(0,7,'Languages Known',0,0,'C');
    $pdf->Ln();
    $pdf->Cell(40,7,'Language',1,0,'C');
    $pdf->Cell(80,7, 'Speak',1,0,'C');
    $pdf->Cell(30,7,'Read',1,0,'C');
    $pdf->Cell(40,7, 'Write',1,0,'C');
    $pdf->Ln();
    for($i = 0; $i < count(array_filter($_POST['txt_langg'])); $i++) {
        $pdf->Cell(40,7,$_POST['txt_langg'][$i],1,0,'L');

        $speak = (isset($_POST['speakk'][$i])) ? 'Yes' : 'No';
        $read = (isset($_POST['read'][$i])) ? 'Yes' : 'No';
        $write = (isset($_POST['write'][$i])) ? 'Yes' : 'No';

        $pdf->Cell(80,7, $speak,1,0,'L');
        $pdf->Cell(30,7, $read,1,0,'L');
        $pdf->Cell(40,7, $write,1,0,'L');
        $pdf->Ln();
    }
    $pdf->Ln();
    $pdf->Cell(0,7,'Work Experience',0,0,'C');
    $pdf->Ln();
    for($i=0; $i < count(array_filter($_POST['txt_companyname'])); $i++) {
        $pdf->Cell(190,0,'','T');
        $pdf->Ln();
        $pdf->Cell(50,7,'Company Name & Address','LR',0,'L');
        $pdf->Cell(140,7, $_POST['txt_companyname'][$i],'LR',0,'L');
        $pdf->Ln();
        $pdf->Cell(50,7,'Position Held','LR',0,'L');
        $pdf->Cell(140,7, $_POST['txt_position'][$i],'LR',0,'L');
        $pdf->Ln();
        $pdf->Cell(50,7,'Company Phone Number','LR',0,'L');
        $pdf->Cell(140,7, $_POST['txt_comp'][$i],'LR',0,'L');
        $pdf->Ln();
        $pdf->Cell(50,7,'Immediate Supervisor name','LR',0,'L');
        $pdf->Cell(140,7, $_POST['txt_super'][$i],'LR',0,'L');
        $pdf->Ln();
        $pdf->Cell(50,7,'Period (From - To)','LR',0,'L');
        $pdf->Cell(140,7, $_POST['txt_period'][$i],'LR',0,'L');
        $pdf->Ln();
        $pdf->Cell(50,7,'Gross Salary','LR',0,'L');
        $pdf->Cell(140,7, $_POST['txt_gross_salary'][$i],'LR',0,'L');
        $pdf->Ln();
        $pdf->Cell(50,7,'Brief Job Description','LR',0,'L');
        $pdf->Cell(140,7, $_POST['txt_job_desc'][$i],'LR',0,'L');
        $pdf->Ln();
        $pdf->Cell(50,7,'Can we contact employer?','LR',0,'L');
        $pdf->Cell(140,7, $_POST['txt_emp'][$i],'LR',0,'L');
        $pdf->Ln();
        $pdf->Cell(190,0,'','T');
        $pdf->Ln();
        /* $pdf->Cell(25,7,'Company Name',1,0,'C');
        $pdf->Cell(25,7, 'Position',1,0,'C');
        $pdf->Cell(25,7,'Ph Num',1,0,'C');
        $pdf->Cell(25,7, 'Supervisor',1,0,'C');
        $pdf->Cell(25,7,'Period',1,0,'C');
        $pdf->Cell(25,7, 'Salary',1,0,'C');
        $pdf->Cell(25,7,'Job Description',1,0,'C');
        $pdf->Cell(25,7, 'Can we contact this employer?',1,0,'C');
        $pdf->Ln(); */
    }

    $pdf->Cell(0,7,'Membership of Professional / Political / Social Bodies',0,0,'L');
    $pdf->Ln();
    $pdf->Cell(0,7, $_POST['txt_members'],0,0,'L');
    $pdf->Ln();
    $pdf->Cell(0,7,'Any Major Sickness or Accident (If Applicable, give details)',0,0,'L');
    $pdf->Ln();
    $pdf->Cell(0,7, $_POST['txt_accident'],0,0,'L');
    $pdf->Ln();
    $pdf->Cell(0,7,'Were you involved in any litigation? (If Applicable, give details)',0,0,'L');
    $pdf->Ln();
    $pdf->Cell(0,7, $_POST['txt_litigation'],0,0,'L');
    $pdf->Ln();
    $pdf->Cell(0,7,'PROFESSIONAL REFERENCES (OTHER THAN RELATIVES & FAMILY FRIENDS)',0,0,'C');
    $pdf->Ln();
    $pdf->Cell(60,7,'Name',1,0,'C');
    $pdf->Cell(90,7, 'Address / Mobile',1,0,'C');
    $pdf->Cell(40,7,'How do you know',1,0,'C');
    $pdf->Ln();
    for($i = 0; $i < count(array_filter($_POST['pro_ref_name'])); $i++) {
        $pdf->Cell(60,7, $_POST['pro_ref_name'][$i],1,0,'L');
        $pdf->Cell(90,7, $_POST['pro_ref_add'][$i],1,0,'L');
        $pdf->Cell(40,7, $_POST['pro_ref_how'][$i],1,0,'L');
        $pdf->Ln();
    }
    $pdf->Ln();
    $file = $pdf->Output('S');

    require("includes/class.phpmailer.php");

    $mail = new PHPMailer();

    $mail->IsSMTP();  // telling the class to use SMTP

    /*$mail->SMTPDebug = 0;
    $mail->Host = "smtp.gmail.com";
    $mail->SMTPAuth = true;                          
    $mail->Username = "webenquiry@forceindiapharma.com";                 
    $mail->Password = "password@1234";                           
    $mail->SMTPSecure = "tls";                           
    $mail->Port = 587;*/                                 

    $mail->From     = "webenquiry@forceindiapharma.com";
    $mail->FromName = 'Force India Pharma';
    $mail->AddAddress("support@codesensesoftsolutions.com");

    $mail->Subject  = "Job Application";
    $mail->Body     = "Hi! \n\n You have received a job application Please find the attachment.";
    $mail->WordWrap = 50;
    $mail->addStringAttachment($file,'Job Application','base64', 'application/pdf');
    $mail->send();

}

?>


删除此
$mail->IsSMTP()
因为您似乎正在使用
sendmail()
而不是SMTP发送电子邮件。

启用并检查是否有错误。感谢replay@TomUdding,我没有收到任何错误。请尝试
$mail->SMTPDebug=1
$mail->SMTPDebug=2查看它是否打印任何显示HTTP错误500错误的内容