Recibir EMAILS ayudaa
Publicado por Elian (1 intervención) el 20/04/2020 20:45:05
Hola me dejaron de tarea configurar este codigo para que pueda recibir mails pero la verdad con esto de la cuarentena no tenemos ni idea de como hacerlo si no han dado clases, nos dejaron a la deriva jajajja... alguien me pueda ayudar??
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
class Email_reader {
// imap server connection
public $conn;
// inbox storage and inbox message count
private $inbox;
private $msg_cnt;
// email login credentials
private $server;
private $user;
private $pass;
private $port;
// connect to the server and get the inbox emails
function __construct($server,$user,$pass,$port=143) {
$this->server=$server;
$this->user=$user;
$this->pass=$pass;
$this->connect();
$this->inbox();
}
// close the server connection
function close() {
$this->inbox = array();
$this->msg_cnt = 0;
imap_close($this->conn);
}
// open the server connection
// the imap_open function parameters will need to be changed for the particular server
// these are laid out to connect to a Dreamhost IMAP server
function connect() {
$this->conn = @imap_open('{'.$this->server/notls}'', $this->user, $this->pass);
}
// return true if connect() correctly
function isConnected() {
if($this->conn)
return true;
return false;
}
// get a specific message (1 = first email, 2 = second email, etc.)
function getMessage($msg_index=NULL) {
if (!$this->isConnected || count($this->inbox) <= 0) {
return array();
}
elseif ( ! is_null($msg_index) && isset($this->inbox[$msg_index])) {
return $this->inbox[$msg_index];
}
return $this->inbox[0];
}
// return the messages in inbox folder
function getMessageNumber() {
if (!$this->isConnected) {
return;
}
return $this->msg_cnt;
}
// read all messages in the inbox folder
function inbox() {
if (!$this->conn) {
return;
}
$this->msg_cnt = imap_num_msg($this->conn);
$in = array();
for($i = 1; $i <= $this->msg_cnt; $i++) {
$in[] = array(
'index' => $i,
'header' => imap_headerinfo($this->conn, $i),
'body' => imap_body($this->conn, $i),
'structure' => imap_fetchstructure($this->conn, $i)
);
}
$this->inbox = $in;
}
}
// iniamos la clase
$mail=new Email_reader('server', 'usuario@dominio.com', 'clave');
if($mail->isConnected) {
echo "Error en la conexion";
return;
}
echo "Hay ".$mail->getMessageNumber()." mensajes en la bandeja de entrada";
// mostramos el contenido del primer mensaje
echo "<pre>";
print_r($mail->getMessage(1));
echo "</pre>";
Valora esta pregunta


0