0

This is my site --> nodeiterator.pl

Why when I send email WITHOUT $mail->addAttachment($file); I DO receive email but... when I add $mail->addAttachment($file); I DO NOT receive email on my mailbox even though I receive sussess message...What Am I missing here? My aim is to send form result to my mail box WITH attachement file...

Below This is my PHP script responsible for sending message:

<?php
    $msg = "";
    use PHPMailer\PHPMailer\PHPMailer;
    include_once "phpmailer/PHPMailer.php";
    include_once "phpmailer/Exception.php";



    if (isset($_POST['submit'])) {

    $email = $_POST['email'];
    $nazwisko = $_POST['nazwisko'];
    $imie = $_POST['imie'];


        if (isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != "") {
            $file = "attachment/" . basename($_FILES['attachment']['name']);
            move_uploaded_file($_FILES['attachment']['tmp_name'], $file);
        } else
            $file = "";

        $mail = new PHPMailer();




        $message  = "
            <html>
                <head>
                    <meta charset=\"utf-8\">
                </head>
                <style type='text/css'>
                    body {font-family:sans-serif; color:#222; padding:20px;}
                    div {margin-bottom:10px;}
                    .msg-title {margin-top:30px;}
                    table {
  border-collapse:collapse;
}
                </style>
                <body>
                    <table border=\"2\">
                    <tr>
                        <td>Nazwisko osoby ubezpiecząjacej :</td>
                        <td>$nazwisko</td>                        
                    </tr>

                    </table>
                </body>
            </html>";      


        $mail->addAddress('piterdeja@gmail.com');
        $mail->setFrom($email);
        $mail->isHTML(true);
        $mail->Body = $message;
        $mail->addAttachment($file); 
                $mail->AllowEmpty = true;



        if ($mail->send())
            $msg = "Your email has been sent, thank you!";
        else
            $msg = "Please try again!";

        unlink($file);
    }
?>
Piotr
  • 343
  • 1
  • 6
  • 14
  • Have a look at this [question](https://stackoverflow.com/questions/371/how-do-you-make-sure-email-you-send-programmatically-is-not-automatically-marked) – DarkBee Nov 02 '17 at 15:29
  • Check the return value of `addAttachment()`, don't just assume it works. – Synchro Nov 02 '17 at 16:27

0 Answers0