Ver Mensaje Individual
  #1 (permalink)  
Antiguo 14/09/2012, 19:20
el_entrepreneur
 
Fecha de Ingreso: julio-2011
Mensajes: 29
Antigüedad: 12 años, 9 meses
Puntos: 1
insertar 1 imagen en funcion mail()

hola, este es mi codigo, alguien puede decirme como insertar una imagen? que falta agregar? cual es la ruta correcta ? porque en este codifo solo adjunto 3 imagenes, pero las quiero agregar con las etiquetas <img>

es por trabajo asique me sirve TODO.

Código PHP:
Ver original
  1. <?php
  2.  
  3. // array with filenames to be sent as attachment
  4. $files = array("1.png","2.png","3.png");
  5.  
  6. // email fields: to, from, subject, and so on
  7. $from = "[email protected]";
  8. $subject ="My subject";
  9. $message = "<html><head></head><body>";
  10. $message .= "<img src='1.png' alt='' /></body></html>";
  11. $headers = "From: $from";
  12.  
  13. // boundary
  14. $semi_rand = md5(time());
  15. $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  16.  
  17. // headers for attachment
  18. $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
  19.  
  20. // multipart boundary
  21. $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
  22. $message .= "--{$mime_boundary}\n";
  23.  
  24. // preparing attachments
  25. for($x=0;$x<count($files);$x++){
  26.     $file = fopen($files[$x],"rb");
  27.     $data = fread($file,filesize($files[$x]));
  28.     fclose($file);
  29.     $data = chunk_split(base64_encode($data));
  30.     $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" .
  31.     "Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" .
  32.     "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
  33.     $message .= "--{$mime_boundary}\n";
  34. }
  35.  
  36. // send
  37.  
  38. $ok = @mail($to, $subject, $message, $headers);
  39. if ($ok) {
  40.     echo "<p>mail sent to $to!</p>";
  41. } else {
  42.     echo "<p>mail could not be sent!</p>";
  43. }
  44.  
  45. ?>

Última edición por el_entrepreneur; 14/09/2012 a las 19:22 Razón: me olvidede algo