Pdf is not sent as an application

I created a php send email script to send pdf via php mailer along with attachments that I can’t send attachments when I send an email, the attached file does not work, please take a look at my code and let me know what error I am making why attachments are not sent properly

Here is my html

<form method="POST" action="details.php?id=<?php echo $_GET['id']; ?>" enctype="multipart/form-data">
    <div class="col col_center">
        <input name="first_name" class="firstname text_input" type="text" placeholder="First Name">
    </div>
    <div class="col col_center">
        <input name="last_name" class="lastname text_input" type="text" placeholder="Last Name">
    </div>
    <div class="col col_center">
        <input name="email" class="email_address text_input" type="email" placeholder="Email Address">
    </div>
    <div class="col col_center">
        <input name="phone" class="phone text_input" type="tel" placeholder="Phone (with country code)">
    </div>
    <input type="hidden" name="title" value="<?php echo $dt['job_title']; ?>" />
    <div class="btn_row">
        <input type="file" value="Attach CV" class="button blue" name="resume" style="width:auto;">
    </div>
    <div class="btn_row">
        <input type="submit" value="Send" name="submit_resume" class="button" style="width:auto;">
    </div>
</form>

This is my php file

$path     = "./uploads/";
    $head     = $_FILES["resume"]["name"];
    $headtype = $_FILES["resume"]["type"];
    $headtemp = $_FILES["resume"]["tmp_name"];

    move_uploaded_file($headtemp, $path.$head);

 $mail = new PHPMailer;
    $client_email = $dt[3];
    $mail->setFrom('noreply@xpertius.com', 'No reply');
    $mail->addAddress("$client_email", 'Xpertius');
    $mail->Subject = "Thank You For Appling - '".$job_title."'";
    $mail->msgHTML($htmlbody);
    $uploadfile1 = tempnam(sys_get_temp_dir(), sha1($_FILES['resume']['name']));
    move_uploaded_file($_FILES['resume']['tmp_name'], $uploadfile1);
    $mail->addAttachment($uploadfile1, $head);

I also tried to save it in the y database, and the file will be saved correctly, but will not be sent, because the attached link to the file is broken in the letter

+4
source share
2 answers

You are trying to move the downloaded file:

move_uploaded_file($_FILES['resume']['tmp_name'], $uploadfile1);

But you have already moved it to:

move_uploaded_file($headtemp, $path.$head);

, , , ( ), , .

, $uploadfile1 :

$uploadfile1 = $path.$head;

move_uploaded_file.

+2

 $mail->AddAttachment($_FILES["resume"]['tmp_name'],
                     $_FILES["resume"]['name']);

, ,

0

Source: https://habr.com/ru/post/1657755/


All Articles