Hello,
I’m having difficulties with this code that I have created and it seems to not want to send and email with the following code. I’ve added screenshots to see it visually to see what I’m trying to accomplish. Go daddy is very limited on adding buttons, file uploads drop downs, ect. So I’m having to build the form from scratch.
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Upload Image via Email</title>
</head>
<body>
<h2>Upload Image</h2>
<form action="submit_form.php" method="post" enctype="multipart/form-data">
<label for="image">.PNG Transparent files ( No Background )</label>
<br>
<br>
Transfer Size:
<select name="Transfers" id="Transfers">
<option value="infant">Infant</option>
<option value="Toddler">Toddler</option>
<option value="Youth">Youth</option>
<option value="Adult">Adult</option>
<option value="Extra Adult">Extra Adult</option>
<option value="Oversized Adult">Oversized Adult</option>
</select>
<br>
<br>
<label for="image">Select Image:</label>
<input type="file" id="image" name="image" accept="image/*" required><br><br>
<label for="email">Your Email:</label>
<input type="email" id="email" name="email" required><br><br>
<label for="message">Message (optional):</label><br>
<textarea id="message" name="message" rows="4" cols="50"></textarea><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
<br>
<br>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$to_email = "robert.bartosh@hotmail.com"; // Replace with your email address
$from_email = $_POST['email'];
$subject = "New Image Submission";
$message = $_POST['message'];
// File upload handling
$file = $_FILES['image'];
$file_name = $file['name'];
$file_tmp = $file['tmp_name'];
// Attach uploaded file to email
$file_type = $file['type'];
$file_content = file_get_contents($file_tmp);
$file_base64 = base64_encode($file_content);
$file_attachment = chunk_split($file_base64);
// Headers for attachment
$boundary = md5(time());
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: $from_email\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-$boundary\"\r\n";
// Body of the email
$body = "--PHP-mixed-$boundary\r\n";
$body .= "Content-Type: multipart/alternative; boundary=\"PHP-alt-$boundary\"\r\n\r\n";
$body .= "--PHP-alt-$boundary\r\n";
$body .= "Content-Type: text/plain; charset=\"utf-8\"\r\n";
$body .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$body .= "Message: $message\r\n\r\n";
$body .= "--PHP-alt-$boundary\r\n";
$body .= "Content-Type: $file_type; name=\"$file_name\"\r\n";
$body .= "Content-Transfer-Encoding: base64\r\n";
$body .= "Content-Disposition: attachment\r\n\r\n";
$body .= $file_attachment . "\r\n\r\n";
$body .= "--PHP-mixed-$boundary--";
// Send email
if (mail($to_email, $subject, $body, $headers)) {
echo "Email sent successfully.";
} else {
echo "Email sending failed.";
}
}
?>
</br>
Also, I need to have the (Transfer Size) dropdown menu selection from the user to be in the email. I have yet to accomplish that as well. Any help would be appreciated.