note 48148 added to function.base64-encode
| From: | sebastian at webcom dot com dot mx | Date: | Mon, 13 Dec 2004 21:57:54 +0000 |
| Subject: | note 48148 added to function.base64-encode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-81768@lists.php.net to get a copy of this message | ||
//Este es un ejemplo para el envio de varios attachments en la funcion mail.
<?PHP
$todas_tus_variables = $_POST['todas_las_variables_post'];
// si la verificacion falla, regresa error.html
if ($validationfailed == true) {
header("Location: error.html");
exit;
}
//aqui va la cabecera del e-mail
//lo que sigue a continuacion es importante, ya que declara el delimitador de la parte del e-mail
//en este caso, el boundary es "BOUNDRY_ATTACH", seguido de un salto de carro.
$email_header = "From: $variable_del_email\n"
. "Reply-To: $variable_del_email\n"
. "MIME-Version: 1.0\n"
. "Content-Type: multipart/mixed; boundary=\"BOUNDRY_ATTACH\"\n"
. "This is a multi-part Content MIME format.\n";
//aqui se hace la verificacion de que el aqchivo se encuentra en base64, en el html, debes de
declarar un campo de type="file" com name="file0"; asi subsecuentemente, hasta
el numero de archivos que podras adjuntar.
if (file_exists($_FILES['file0']['tmp_name']) === true) {
$filename0 = $_FILES['file0']['tmp_name'];
$filehandle0 = fopen($filename0, "r");
$fileattach0 = fread($filehandle0, filesize ($filename0));
fclose($filehandle0);
$fileattach0 = chunk_split(base64_encode($fileattach0));
}
//esta es la sentencia para verificar el 2do archivo.
if (file_exists($_FILES['file1']['tmp_name']) === true) {
$filename1 = $_FILES['file1']['tmp_name'];
$filehandle1 = fopen($filename1, "r");
$fileattach1 = fread($filehandle1, filesize ($filename1));
fclose($filehandle1);
$fileattach1 = chunk_split(base64_encode($fileattach1));
}
//para salto de campo es necesario indicar la etiqueta de fin de sección
"--BOUNDRY_ATTACH\n", declarada en el header.
$email_body = "--BOUNDRY_ATTACH\n"
. "Content-Type: text/plain; charset=\"iso-8859-1\"\n"
. "Content-Transfer-Encoding: quoted-printable\n"
. "\n"
. "--CONTENIDO DEL MENSAJE--";
//esta es la parte en donde nuestro php incluira los archivos adjuntos al mensaje, delimitados por
la etiqueta: "--BOUNDRY_ATTACH\n"
//primer archivo:
if (file_exists($_FILES['file0']['tmp_name']) === true) {
$email_body .= "\n--BOUNDRY_ATTACH\nContent-Type: " .
$_FILES['file0']['type'] . "; name=\"" .
$_FILES['file0']['name'] . "\"\n"
. "Content-disposition: attachment\n"
. "Content-transfer-encoding: base64\n"
. "\n"
. "$fileattach0\n";
}
//segundo archivo:
if (file_exists($_FILES['file1']['tmp_name']) === true) {
$email_body .= "\n--BOUNDRY_ATTACH\nContent-Type: " .
$_FILES['file1']['type'] . "; name=\"" .
$_FILES['file1']['name'] . "\"\n"
. "Content-disposition: attachment\n"
. "Content-transfer-encoding: base64\n"
. "\n"
. "$fileattach1\n";
}
//incluyes la funcion mail y listo
mail("tudireccion@tusubdominio.tudominio", "TITULO DEL MENSAJE (SUBJECT)",
$email_body, "$email_header");
//hace la llamada a el archivo de envio satisfactorio.
header("Location: ok.php");
exit;
?>
----
Manual Page -- http://www.php.net/manual/en/function.base64-encode.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48148
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48148&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48148&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48148&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48148&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48148&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48148&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48148&report=yes
Search -- http://master.php.net/manage/user-notes.php