Ver Mensaje Individual
  #3 (permalink)  
Antiguo 31/01/2002, 09:55
Avatar de chubu
chubu
 
Fecha de Ingreso: enero-2002
Ubicación: Buenos Aires
Mensajes: 133
Antigüedad: 22 años, 3 meses
Puntos: 0
Re: Attachs con la funcion mail()

esto seria un codigo muy "sencillo" que hace el trabajo

<pre>
&lt;?
if(isset($mandomail))
{
print(&quot;&lt;b&gt;To:&lt;/b&gt; $mail_to&lt;br&gt;&quot;);
print(&quot;&lt;b&gt;From:&lt;/b&gt; $mail_from&lt;br&gt;&quot;);
print(&quot;&lt;b&gt;Subject:&lt;/b&gt; $mail_subject&lt;br&gt;&quot;);
print(&quot;&lt;b&gt;Body:&lt;/b&gt;&lt;br&gt;$mail_body&lt;br&gt;&quot;);
print(&quot;&lt;b&gt;Attach:&lt;/b&gt; $attach_name&lt;br&gt;&quot;);

$headers = &quot;MIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=\&quot;XX-1234DED00099A\&quot;;\nContent-Transfer-Encoding: 7bit&quot;;

$body = &quot;This is a MIME Encoded Message\n\n--XX-1234DED00099A\nContent-Type: text/plain; charset=us-ascii\nContent-Transfer-Encoding: 7bit\n\n&quot; .
$mail_body . &quot;\n&quot;;
//vemos si hay attachment, &quot;none&quot; es el valor que el php le asigna al nombre cuando no se subio archivo
if(($attach != &quot;none&quot;) &amp;&amp; (is_uploaded_file($attach)))
{
$uf = fopen($attach, &quot;r&quot;);
$buffer = &quot;&quot;;
while (!feof($uf))
{
$buffer .= fread($uf,4096);
}
$buffer = chunk_split(base64_encode($buffer));
$body .= &quot;\n--XX-1234DED00099A\nContent-Type: $attach_type; name=\&quot;$attach_name\&quot;\nContent-Transfer-Encoding: base64\n\n&quot; .
$buffer . &quot;\n&quot;;
}

print(&quot;&lt;pre&gt;$body&lt;/pre&gt;&quot;);

if(mail($mail_to,$mail_subject,$body,&quot;From: $mail_from\n&quot;.$headers))
{
print(&quot;&lt;br&gt;enviado!!!&lt;br&gt;&quot;);
}
else
{
print(&quot;&lt;br&gt;ERROR!!!&lt;br&gt;&quot;);
}
}
?&gt;
&lt;form action=&quot;&lt;?=$PHP_SELF?&gt;&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;
&lt;input type=&quot;hidden&quot; name=&quot;mandomail&quot; value=&quot;si&quot;&gt;
To:&amp;nbsp;&lt;input type=&quot;text&quot; name=&quot;mail_to&quot;&gt;&lt;br&gt;
From:&amp;nbsp;&lt;input type=&quot;text&quot; name=&quot;mail_from&quot;&gt;&lt;br&gt;
Subject:&amp;nbsp;&lt;input type=&quot;text&quot; name=&quot;mail_subject&quot;&gt;&lt;br&gt;
&lt;textarea name=&quot;mail_body&quot;&gt;&lt;/textarea&gt;&lt;br&gt;
&lt;input type='file' name='attach'&gt;&lt;br&gt;
&lt;input type=&quot;submit&quot; value=&quot;send&quot;&gt;
&lt;/form&gt;
</pre>