Pergunta

I have a little function, which supposed to be sending an email with the submitted image as attachment. I receive the email, that's okay, but the attachment is missing. The PHPMailer isn't trowing any errors, so I don't know what could be the problem.

This is the actual code:

if(isset($_FILES['submitimg']['name'])){

    $messageBody .= "<p>Bla bla bla:</p>";
    $messageBody .= "<p>Bla name: ".$_POST['submitname']."</p>";
    $messageBody .= "<p>Bla email: ".$_POST['submitemail']."</p>";

    $mail = new PHPMailer();
    $mail->CharSet = 'UTF-8';
    $mail->setFrom('blab@blabla.com', 'Bla bla');
    $mail->addAddress($adminEmail, $adminName);
    $mail->Subject = 'New blabla';
    $mail->Body = $messageBody;

    $fileName = $_FILES['submitimg']['name'];
    $filePath = $_FILES['submitimg']['tmpname'];

    $mail->addAttachment($filePath, $fileName);

    if (!$mail->send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    }
}

Can someone help me out, please? :)

Thank you very much!

Foi útil?

Solução

Okay, I found the solution. It was a simple typo:

$filePath = $_FILES['submitimg']['tmp_name'];

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top