gpt4 book ai didi

用于阅读电子邮件的 PHP 库

转载 作者:可可西里 更新时间:2023-10-31 22:44:37 24 4
gpt4 key购买 nike

我目前使用 SwiftMailer 库来发送 电子邮件,但不幸的是它只能用于发送,不能用于接收。我想知道...是否有类似的库可以通过 IMAP 连接到电子邮件帐户并阅读电子邮件(IE 使我能够循环浏览电子邮件)。我知道这里有一组 PHP IMAP 函数:http://us3.php.net/manual/en/book.imap.php

但我的问题是,有人知道用于接收/查看所有电子邮件的替代库或 IMAP 包装类吗?

我真的找不到任何东西,在此先感谢。

最佳答案

请看下面你的:--

http://www.php.net/mailparse

http://garrettstjohn.com/entry/reading-emails-with-php/

或者试试看:-

使用 PHP 阅读电子邮件

<?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 = 'yourserver.com';
private $user = 'email@yourserver.com';
private $pass = 'yourpassword';
private $port = 143; // adjust according to server settings

// connect to the server and get the inbox emails
function __construct() {
$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);
}

// move the message to a new folder
function move($msg_index, $folder='INBOX.Processed') {
// move on server
imap_mail_move($this->conn, $msg_index, $folder);
imap_expunge($this->conn);

// re-read the inbox
$this->inbox();
}

// get a specific message (1 = first email, 2 = second email, etc.)
function get($msg_index=NULL) {
if (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];
}

// read the inbox
function inbox() {
$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;
}

}

?>

关于用于阅读电子邮件的 PHP 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11872643/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com