Follow along with the video below to see how to install our site as a web app on your home screen.
Примечание: This feature may not be available in some browsers.
<?php
// Для отправки сообщения
$imap = new imap();
$imap->from = "my name <my@email>";
$imap->attachFile("/path/to/your/file");
$imap->sendMessage("send.to@address.com", "my subject", "my <b>html</b> message");
class imap
{
var $from = "";
var $to = "";
var $cc = "";
var $msgFooter = "";
// protected from public
protected $body = array(
// should start with 1... just in case ;)
1 => array(
"type" => TYPEMULTIPART, // we only send multipart
"subtype" => "mixed" // mixed formats
)
);
// someone calls class without any function
function __toString()
{
return "rsIMAP v0.3";
}
// attach file to message composition
function attachFile($filename)
{
$contents = file_get_contents($filename);
$x = count($this->body) + 1; // next part
$this->body[$x] = array();
$this->body[$x]["contents.data"] = $contents;
$this->body[$x]["disposition.type"] = "attachment"; // type is attachment
$this->body[$x]["disposition"] = array ("filename" => basename($filename)); // filename
}
// create imap mbox object
function getMbox($user, $pass, $host = "localhost", $port = 110, $box = "INBOX", $type = "pop3")
{
$mbox = imap_open("{".$host.":".$port."/".$type."}".$box, $user, $pass);
return $mbox;
}
// send message
function sendMessage($to, $subject, $message)
{
$this->to = $to;
// assemble envelop
$envelop = array (
"from" => $this->from,
"to" => $this->to,
"cc" => $this->cc
);
$x = count($this->body) + 1; // next part
$this->body[$x] = array();
$this->body[$x]["type"] = "text"; // text
$this->body[$x]["subtype"] = "html"; // sending in html
$this->body[$x]["description"] = "Message body"; // just a description for this part can skip it
// footer of message is in $this->msgFooter;
$this->body[$x]["contents.data"] = $message . $this->msgFooter;
// assemble message from parts
$message = imap_mail_compose($envelop, $this->body);
list($t_header, $t_body) = split("\r\n\r\n", $message, 2); // split headers and body
$t_header = str_replace("\r",'', $t_header);
// send it now
return imap_mail($to, $subject, $t_body, $t_header);
}
// retrieve message by it's id
function getMessage($mbox, $messageid)
{
$message = array(); // it's an array
// get headers for message
$header = imap_header($mbox, $messageid);
$structure = imap_fetchstructure($mbox, $messageid); // structure
// assign variables
$message['subject'] = $header->subject;
$message['fromname'] = $header->from[0]->personal;
$message['fromaddress'] = $header->from[0]->mailbox . "@" . $header->from[0]->host;
$message['toaddress'] = $header->toaddress;
$message['ccaddress'] = $header->ccaddress;
$message['date'] = $header->date;
// do we have any attachments?
$parts = $structure->parts;
$numparts = count($parts);
if ($numparts > 1) // yes we do
{
$endwhile = false;
$stack = array();
$content = "";
$attachment = array();
$i = 0;
// for every attachment
while (!$endwhile)
{
if (!$parts[$i])
{
if (count($stack) > 0) // have stacks?
{ // sure we do!
$parts = $stack[count($stack)-1]["p"];
$i = $stack[count($stack)-1]["i"] + 1;
array_pop($stack);
} else { // or no...
$endwhile = true;
}
}
if (!$endwhile) // last loop?
{
$partstring = "";
foreach ($stack as $s)
$partstring .= ($s["i"]+1) . ".";
$partstring .= ($i+1);
if (strtoupper($parts[$i]->disposition) == "ATTACHMENT") // attachment!!
{
$attachment[] = array(
"filename" => $parts[$i]->parameters[0]->value, // filename
"encoding" => $parts[$i]->encoding, // encodign
"filedata" => imap_fetchbody($mbox, $messageid, $partstring) // data, duhh!
);
} elseif (strtoupper($parts[$i]->subtype) == "PLAIN") { // message
$np = imap_fetchbody($mbox, $messageid, $partstring); // parse
$content .= str_replace("\n", "<br>", $np); // add this part
}
}
if ($parts[$i]->parts)
{
$stack[] = array("p" => $parts, "i" => $i); // next stack
$parts = $parts[$i]->parts; // parts
$i = 0;
} else {
$i++;
}
}
} else { // no attachments
$attachment = array();
$content = imap_body($mbox, $messageid);
}
$message['body'] = $content;
$message['attachment'] = $attachment;
return $message; // return message
}
}
?>
Глянь здесь ещё:
*** скрытое содержание ***