PHP - Función imap_fetchstructure ()
Las funciones PHP − IMAP le ayudan a acceder a las cuentas de correo electrónico, IMAP significa IInternet Mafligir Aacceso Protocol al utilizar estas funciones también puede trabajar con protocolos NNTP, POP3 y métodos de acceso al buzón local.
los imap_fetchstructure() La función acepta un valor de recurso que representa un flujo IMAP, un valor entero que representa un mensaje en el buzón como parámetros y lee la estructura del mensaje especificado.
Sintaxis
imap_fetchstructure($imap_stream, $msg [, $options]);
Parámetros
options(Optional)
Este es un parámetro opcional que puede ser uno o más de los siguientes:
FT_UID
FT_PEEK
FT_INTERNAL
No Señor | Descripción de parámetros |
---|---|
1 | imap_stream (Mandatory) Este es un valor de cadena que representa un flujo IMAP, valor de retorno del imap_open() función. |
2 | msg (Mandatory) Este es un valor entero que representa el mensaje / número de correo, que se marcará para su eliminación. |
3 | msg (Mandatory) Este es un valor entero que representa el mensaje / número de correo, que se marcará para su eliminación. |
Valores devueltos
Esta función devuelve un valor de cadena que representa la sección recuperada de un correo / mensaje.
Versión PHP
Esta función se introdujo por primera vez en PHP versión 4 y funciona en todas las versiones posteriores.
Ejemplo
El siguiente ejemplo demuestra el uso de imap_fetchstructure() función -
<html>
<body>
<?php
//Establishing connection
$url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
$id = "[email protected]";
$pwd = "cohondob_123";
$imap = imap_open($url, $id, $pwd);
print("Connection established...."."<br>");
//Fetching the Structure
print("Structure: "."<br>");
$body = imap_fetchstructure($imap, 1);
print_r($body);
//Closing the connection
imap_close($imap);
?>
</body>
</html>
Salida
Esto generará la siguiente salida:
Connection established....
Structure:
stdClass Object (
[type] => 1 [encoding] => 0 [ifsubtype] => 1
[subtype] => ALTERNATIVE [ifdescription] => 0
[ifid] => 0 [ifdisposition] => 0 [ifdparameters] => 0
[ifparameters] => 1 [parameters] =>
Array (
[0] => stdClass Object (
[attribute] => BOUNDARY
[value] => 000000000000a0d34e05b24373f4
)
)
[parts] => Array (
[0] => stdClass Object (
[type] => 0 [encoding] => 0 [ifsubtype] => 1
[subtype] => PLAIN [ifdescription] => 0
[ifid] => 0 [lines] => 1 [bytes] => 15
[ifdisposition] => 0 [ifdparameters] => 0
[ifparameters] => 1 [parameters] => Array (
[0] => stdClass Object (
[attribute] => CHARSET [value] => UTF-8
)
)
)
[1] => stdClass Object (
[type] => 0 [encoding] => 0 [ifsubtype] => 1
[subtype] => HTML [ifdescription] => 0 [ifid] => 0
[lines] => 1 [bytes] => 40 [ifdisposition] => 0
[ifdparameters] => 0 [ifparameters] => 1
[parameters] => Array (
[0] => stdClass Object (
[attribute] => CHARSET [value] => UTF-8
)
)
)
)
)
Ejemplo
A continuación se muestra otro ejemplo de esta función:
<html>
<body>
<?php
//Establishing connection
$url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
$id = "[email protected]";
$pwd = "cohondob_123";
$imap = imap_open($url, $id, $pwd);
print("Connection established...."."<br>");
//Searching emails
$emailData = imap_search($imap, '');
if (! empty($emailData)) {
foreach ($emailData as $msg) {
$msg = imap_fetchstructure($imap, $msg);
print($msg."<br>");
}
}
//Closing the connection
imap_close($imap);
?>
</body>
</html>
Salida
Esto generará la siguiente salida:
Connection established....
stdClass Object (
[type] => 1 [encoding] => 0 [ifsubtype] => 1
[subtype] => ALTERNATIVE [ifdescription] => 0
[ifid] => 0 [ifdisposition] => 0 [ifdparameters] => 0
[ifparameters] => 1 [parameters] =>
Array (
[0] => stdClass Object (
[attribute] => BOUNDARY [value] => 000000000000a0d34e05b24373f4
)
)
[parts] =>
Array (
[0] => stdClass Object (
[type] => 0 [encoding] => 0 [ifsubtype] => 1
[subtype] => PLAIN [ifdescription] => 0 [ifid] => 0
[lines] => 1 [bytes] => 15 [ifdisposition] => 0
[ifdparameters] => 0 [ifparameters] => 1
[parameters] => Array (
[0] => stdClass Object (
[attribute] => CHARSET [value] => UTF-8
)
)
)
[1] => stdClass Object (
[type] => 0 [encoding] => 0 [ifsubtype] => 1
[subtype] => HTML [ifdescription] => 0 [ifid] => 0
[lines] => 1 [bytes] => 40 [ifdisposition] => 0
[ifdparameters] => 0 [ifparameters] => 1 [parameters] =>
Array (
[0] => stdClass Object (
[attribute] => CHARSET [value] => UTF-8
)
)
)
)
)
stdClass Object (
[type] => 1 [encoding] => 0 [ifsubtype] => 1
[subtype] => ALTERNATIVE [ifdescription] => 0 [ifid] => 0
[ifdisposition] => 0 [ifdparameters] => 0 [ifparameters] => 1
[parameters] =>
Array (
[0] => stdClass Object (
[attribute] => BOUNDARY [value] => 000000000000bb1b8205b24375b9
)
)
[parts] =>
Array (
[0] => stdClass Object (
[type] => 0 [encoding] => 0 [ifsubtype] => 1
[subtype] => PLAIN [ifdescription] => 0 [ifid] => 0
[lines] => 1 [bytes] => 16 [ifdisposition] => 0
[ifdparameters] => 0 [ifparameters] => 1 [parameters] =>
Array (
[0] => stdClass Object (
[attribute] => CHARSET [value] => UTF-8
)
)
)
[1] => stdClass Object (
[type] => 0 [encoding] => 0
[ifsubtype] => 1 [subtype] => HTML [ifdescription] => 0
[ifid] => 0 [lines] => 1 [bytes] => 42 [ifdisposition] => 0
[ifdparameters] => 0 [ifparameters] => 1 [parameters] =>
Array (
[0] => stdClass Object (
[attribute] => CHARSET [value] => UTF-8
)
)
)
)
)
Ejemplo
A continuación se muestra un ejemplo de la función anterior con parámetros opcionales:
<html>
<body>
<?php
//Establishing connection
$url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
$id = "[email protected]";
$pwd = "cohondob_123";
$imap = imap_open($url, $id, $pwd);
print("Connection established...."."<br>");
//Fetching the Structure
print("Structure: "."<br>");
$body = imap_fetchstructure($imap, imap_uid($imap, 1), FT_UID);
print_r($body);
//Closing the connection
imap_close($imap);
?>
</body>
</html>
Salida
Esto generará la siguiente salida:
Connection established....
Structure:
stdClass Object (
[type] => 1 [encoding] => 0 [ifsubtype] => 1
[subtype] => ALTERNATIVE [ifdescription] => 0 [ifid] => 0
[ifdisposition] => 0 [ifdparameters] => 0 [ifparameters] => 1
[parameters] =>
Array (
[0] => stdClass Object (
[attribute] => BOUNDARY [value] => 000000000000a0d34e05b24373f4
)
)
[parts] =>
Array (
[0] => stdClass Object (
[type] => 0 [encoding] => 0 [ifsubtype] => 1
[subtype] => PLAIN [ifdescription] => 0 [ifid] => 0
[lines] => 1 [bytes] => 15 [ifdisposition] => 0
[ifdparameters] => 0 [ifparameters] => 1 [parameters] =>
Array (
[0] => stdClass Object (
[attribute] => CHARSET [value] => UTF-8
)
)
) [1] => stdClass Object (
[type] => 0 [encoding] => 0
[ifsubtype] => 1 [subtype] => HTML [ifdescription] => 0
[ifid] => 0 [lines] => 1 [bytes] => 40
[ifdisposition] => 0 [ifdparameters] => 0
[ifparameters] => 1 [parameters] =>
Array (
[0] => stdClass Object (
[attribute] => CHARSET [value] => UTF-8
)
)
)
)
)