Hi, is there any php form mail script with file upload like this website ? or like the picture I've attached below, so if you the user submit, it will automatically send to my email? thank you... :)

Dani AI

Generated

Short answer: yes. The usual, reliable pattern is a standard HTML form with enctype="multipart/form-data", server-side validation of the uploaded file, then attach the file to an outgoing message using a mail library such as PHPMailer instead of crafting MIME by hand. asked for an upload-then-email flow; noted a paid solution exists, but a free, maintainable route is to use PHPMailer + a few security checks.

Minimal form and server-side example (illustrative):

<form method="post" enctype="multipart/form-data">
<input type="text" name="name">
<input type="file" name="upload">
<input type="submit" value="Send">
</form>

require 'vendor/autoload.php'; // PHPMailer via Composer

// basic checks
if (!empty($_FILES['upload']) && $_FILES['upload']['error'] === UPLOAD_ERR_OK) {
    $tmp = $_FILES['upload']['tmp_name'];
    $safeName = basename($_FILES['upload']['name']);

    // use finfo to confirm MIME type before attaching
    $finfo = finfo_open(FILEINFO_MIME_TYPE);
    $mime = finfo_file($finfo, $tmp);
    finfo_close($finfo);

    $allowed = ['image/jpeg','image/png','application/pdf'];
    if (in_array($mime, $allowed) && $_FILES['upload']['size'] <= 2*1024*1024) {
        $mail = new PHPMailer\PHPMailer\PHPMailer(true);
        // configure SMTP or use mail() fallback
        $mail->addAddress('owner@example.com');
        $mail->Subject = 'Form upload';
        $mail->Body = $_POST['name'] ?? '';
        $mail->addAttachment($tmp, $safeName);
        $mail->send();
    }
}

Essential cautions and troubleshooting notes: validate both MIME and extension, enforce size limits, use move_uploaded_file() if keeping files on disk, store uploads outside webroot and give them random names, delete temporary copies after sending, and prefer authenticated SMTP (hosts often restrict mail()). If attachments do not arrive, check $_FILES error codes, server upload_max_filesize and post_max_size, mail server attachment size limits, and PHPMailer exceptions.

References for implementation and hardening: PHP file upload docs (file upload overview), move_uploaded_file (doc), finfo_file (doc), PHPMailer (GitHub), and OWASP file upload guidance (cheat sheet).

Recommended Answers

All 2 Replies

Hi, is there any php form script with file upload like this website ? or like the picture I've attached below, so if you the user submit, it will automatically send to my email? thank you... :)

I have searched a lot since two days on google, but Somehow I couldn't find it :/
I need a form with file upload that's send to my email after submitting. :-)

I built one in the past, not free of course.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.