How can a user upload an image through a contact form in PHP and have it sent as an attachment?

To allow users to upload an image through a contact form in PHP and have it sent as an attachment, you need to ensure that the form has an input field of type "file" for image uploads. In the PHP script that processes the form submission, you can use the $_FILES superglobal to access the uploaded image file, move it to a designated folder on the server, and then attach it to the email using PHP's mail function or a library like PHPMailer.

```php
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $image = $_FILES['image']['tmp_name'];
    $image_name = $_FILES['image']['name'];

    $to = "recipient@example.com";
    $subject = "Contact Form Submission with Image Attachment";
    $message = "Here is the image that was uploaded:";
    $headers = "From: sender@example.com";

    $file = $image;
    $content = file_get_contents($file);
    $content = chunk_split(base64_encode($content));
    $uid = md5(uniqid(time()));

    $header = "From: sender@example.com\r\n";
    $header .= "Reply-To: sender@example.com\r\n";
    $header .= "MIME-Version: 1.0\r\n";
    $header .= "Content-Type: multipart/mixed; boundary=\"" . $uid . "\"\r\n\r\n";
    $header .= "This is a multi-part message in MIME format.\r\n";
    $header .= "--" . $uid . "\r\n";
    $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
    $header .= "Content-Transfer-Encoding 7bit\r\n\r\n";
    $header .= $message . "\r\n\r\n";
    $header .= "--" . $uid . "\r\n";
    $header .= "Content-Type: application/octet-stream; name=\"" . $image_name . "\"\r\n";
    $header .= "Content-Transfer-Encoding: base64\r\n";
    $header .= "Content-Disposition: attachment; filename=\"" . $image_name . "\"\r\n\r\n";
    $header .= $content . "\r\n\r\n";
    $header .= "--" . $uid . "--";

    if (mail($to, $subject, "", $header)) {
        echo "Email sent with image attachment successfully.";