Ver Mensaje Individual
  #2 (permalink)  
Antiguo 16/11/2009, 16:21
Avatar de AnesGy
AnesGy
 
Fecha de Ingreso: mayo-2009
Mensajes: 518
Antigüedad: 14 años, 11 meses
Puntos: 19
Respuesta: enviar formulario + imagen a un email

puedes subir tu imagen al servidor (al tuyo) y enviarla como un link, o, si no quieres esto tienes que conocer la forma de encriptar los datos de los email y mandarlo como attachment.

Problema de esto: si usas mail() y la imagen es muy grande no funcionará. Nunca lo he probado pero a veces mail() se bloquea enviando mensajes largos que no creo que ocupen más que una imagen.

Este es parte de un código PHP para enviar mail con attachments, según el autor dice que le funciona bien, pero tampoco se que envía como attachments.

No me lo he leido entero y no estoy seguro de como se usa, si eso te lo miro otro día que hoy estoy cansado.

Código PHP:
Ver original
  1. <?php
  2. $to      = $_POST['to'];
  3. $email   = $_POST['email'];
  4. $name    = $_POST['name'];
  5. $subject = $_POST['subject'];
  6. $comment = $_POST['message'];
  7.  
  8. $To          = strip_tags($to);
  9. $TextMessage =strip_tags(nl2br($comment),"<br>");
  10. $HTMLMessage =nl2br($comment);
  11. $FromName    =strip_tags($name);
  12. $FromEmail   =strip_tags($email);
  13. $Subject     =strip_tags($subject);
  14.  
  15. $boundary1   =rand(0,9)."-"
  16. .rand(10000000000,9999999999)."-"
  17. .rand(10000000000,9999999999)."=:"
  18. .rand(10000,99999);
  19. $boundary2   =rand(0,9)."-".rand(10000000000,9999999999)."-"
  20. .rand(10000000000,9999999999)."=:"
  21. .rand(10000,99999);
  22.  
  23.  
  24. for($i=0; $i < count($_FILES['youfile']['name']); $i++){
  25. if(is_uploaded_file($_FILES['fileatt']['tmp_name'][$i]) &&
  26.    !empty($_FILES['fileatt']['size'][$i]) &&
  27.    !empty($_FILES['fileatt']['name'][$i])){
  28.    
  29. $attach      ='yes';
  30. $end         ='';
  31.  
  32.    $handle      =fopen($_FILES['fileatt']['tmp_name'][$i], 'rb');
  33.    $f_contents  =fread($handle, $_FILES['fileatt']['size'][$i]);
  34.    $attachment[]=chunk_split(base64_encode($f_contents));
  35.    fclose($handle);
  36.  
  37. $ftype[]       =$_FILES['fileatt']['type'][$i];
  38. $fname[]       =$_FILES['fileatt']['name'][$i];
  39. }
  40. }
  41.  
  42. /***************************************************************
  43.  Creating Email: Headers, BODY
  44.  1- HTML Email WIthout Attachment!! <<-------- H T M L ---------
  45.  ***************************************************************/
  46. #---->Headers Part
  47. $Headers     =<<<AKAM
  48. From: $FromName <$FromEmail>
  49. Reply-To: $FromEmail
  50. MIME-Version: 1.0
  51. Content-Type: multipart/alternative;
  52.     boundary="$boundary1"
  53. AKAM;
  54.  
  55. #---->BODY Part
  56. $Body        =<<<AKAM
  57. MIME-Version: 1.0
  58. Content-Type: multipart/alternative;
  59.     boundary="$boundary1"
  60.  
  61. This is a multi-part message in MIME format.
  62.  
  63. --$boundary1
  64. Content-Type: text/plain;
  65.     charset="windows-1256"
  66. Content-Transfer-Encoding: quoted-printable
  67.  
  68. $TextMessage
  69. --$boundary1
  70. Content-Type: text/html;
  71.     charset="windows-1256"
  72. Content-Transfer-Encoding: quoted-printable
  73.  
  74. $HTMLMessage
  75.  
  76. --$boundary1--
  77. AKAM;
  78.  
  79. /***************************************************************
  80.  2- HTML Email WIth Multiple Attachment <<----- Attachment ------
  81.  ***************************************************************/
  82.  
  83. if($attach=='yes') {
  84.  
  85. $attachments='';
  86. $Headers     =<<<AKAM
  87. From: $FromName <$FromEmail>
  88. Reply-To: $FromEmail
  89. MIME-Version: 1.0
  90. Content-Type: multipart/mixed;
  91.     boundary="$boundary1"
  92. AKAM;
  93.  
  94. for($j=0;$j<count($ftype); $j++){
  95. $attachments.=<<<ATTA
  96. --$boundary1
  97. Content-Type: $ftype[$j];
  98.     name="$fname[$i]"
  99. Content-Transfer-Encoding: base64
  100. Content-Disposition: attachment;
  101.     filename="$fname[$j]"
  102.  
  103. $attachment[$j]
  104.  
  105. ATTA;
  106. }
  107.  
  108. $Body        =<<<AKAM
  109. This is a multi-part message in MIME format.
  110.  
  111. --$boundary1
  112. Content-Type: multipart/alternative;
  113.     boundary="$boundary2"
  114.  
  115. --$boundary2
  116. Content-Type: text/plain;
  117.     charset="windows-1256"
  118. Content-Transfer-Encoding: quoted-printable
  119.  
  120. $TextMessage
  121. --$boundary2
  122. Content-Type: text/html;
  123.     charset="windows-1256"
  124. Content-Transfer-Encoding: quoted-printable
  125.  
  126. $HTMLMessage
  127.  
  128. --$boundary2--
  129.  
  130. $attachments
  131. --$boundary1--
  132. AKAM;
  133. }
  134.  
  135. /***************************************************************
  136.  Sending Email
  137.  ***************************************************************/
  138. $ok=mail($To, $Subject, $Body, $Headers);
  139. echo $ok?"<h1> Mail Sent</h1>":"<h1> Mail not SEND</h1>";
  140. ?>
__________________
Si alguna vez parece que soy grosero, pido perdón, es un intento fallido de ser directo.

AnesGy SD. Name it, Get it