08. oktober 2003 - 10:49Der er
11 kommentarer og 1 løsning
Send billede i email via form (PHP)
Hej.
Jeg står og skal til at give mulighed for at sende en email via en form. Til dette billede skal kunne vedhæftes et billede. Men hvordan kan jeg sende et sådan billede efter endt upload ?
AI bliver først for alvor en del af arbejdet, når teknologien integreres i den måde, vi arbejder på. At have adgang til AI betyder ikke nødvendigvis, at medarbejderne er klar til at bruge den.
ok :o) Vidste jeg ikke.. jeg syntes bare at det var lidt for meget at skrive...
Here goes:
<?php # If the user has pushed the "Send" button: if ($send) { $body = $message; $to="your-email@ddress.dk"; //your email address # Defining the boundary: $boundary = uniqid( "");
# Making the headers: $headers = "From: $name <$from> Content-type: multipart/mixed; boundary=\"$boundary\""; if ($attachment=="") {} else { # Determining the MIME type of the uploaded file: if ($attachment_type) $mimeType = $attachment_type; # If the browser did not specify the MIME type of the uploaded # file, we'll just set the MIME type to "application/unknown". else $mimeType = "application/unknown";
# Determining the file name: $fileName = $attachment_name;
# Opening the file: $fp = fopen($attachment, "r"); # Reading the entire file into a variable: $read = fread($fp, filesize($attachment));
# OK, now we have a variable named $read # that contains the entire file as a text chunk. # Now we need to convert that text chunk into # something that the mail clients can read. # This means we'll have to encode it with base64. $read = base64_encode($read);
# Now we've got a long text base64 encoded # text string. The next thing we need to do # is to convert that long string to # small pieces consisting of 76 characters # per line. $read = chunk_split($read);
# Now we can create the mail body: $body = "--$boundary Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 8bit
ups... og vær lige så venlig at ændre delen med : # Mailing the whole thing: mail($to, $subject, $body, $headers, "-fjakob@brynitz.dk" ); til: # Mailing the whole thing: mail($to, $subject, $body, $headers, "-fdin-email@ddress.dk" );
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.