Jump to content

Upload temp image files, resize them and email as atachments


AgentAlmond

Recommended Posts

Hi Everyone!

I'm new to php and am trying to get to a specific place an not having much luck!

I (ideally) would like to be able to upload 3 image files on a webpage and have my php script resize it and then add it as 3 attachments with a load of other info in an email....

Its driving me a little insane though! I can't seem to get this code to fit with some resizing code, If you more experienced guys could point me in the right direction that would be awesome!

I think i can get something in that for loop to resize as it attaches but everything i try messes up!

<?php
  if($_POST['formSubmit'] == "Submit")
  {
    if($_POST['text_question'] == "" || $_POST['text_name'] == "" || $_POST['text_email'] == "")
  {

header("Location: back.html");
 
  }else{
  $from = $_POST['text_email'];
    $to = "alex@camppontiac.com";
$subject = "Website Consultation";
$message = ($_POST['text_question']);
$message .= "\n----------------\n";
$message .= "From: \n" . $_POST['text_name'] . "\nE-mail address: \n" . $_POST['text_email'] . "\nPhone Number:\n" . $_POST['text_phone'];
$headers = "From: " . $_POST['text_name'] . " <" . $_POST['text_email'] . ">";
$dir = "/tmp";
$dh  = opendir($dir);
while (false !== ($filename = readdir($dh))) {
    $files[] = $filename;
}


// include the from email in the headers
$headers = "From: $from";

// boundary
$time = md5(time());
$boundary = "==Multipart_Boundary_x{$time}x";

// headers used for send attachment with email
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$boundary}\"";

// multipart boundary
$message = "--{$boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
$message .= "--{$boundary}\n";

// attach the attachments to the message
for($x=0; $x<count($files); $x++){
    $files = fopen($files[$x],"w+");
    $content = fread($file,filesize($files[$x]));
    fclose($file);
    $content = chunk_split(base64_encode($content));
    $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" .
        "Content-Disposition: attachment;\n" . " filename=\"$filenames[$x]\"\n" .
        "Content-Transfer-Encoding: base64\n\n" . $content . "\n\n";
    $message .= "--{$boundary}\n";
}

// sending mail

if(@mail($to, $subject, $message, $headers)== true)
{
  header("Location: confirm.html");
}
else
{
  header("Location: back.html");
}
  }}
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.