PHP讀取郵件的方法有多種,以下是一些常用的方法:
$connection = imap_open("{mail.example.com:993/ssl}", "username", "password");
$mails = imap_search($connection, "ALL");
foreach ($mails as $mailId) {
$header = imap_headerinfo($connection, $mailId);
$subject = $header->subject;
$from = $header->fromaddress;
// 其他操作...
}
imap_close($connection);
$connection = pop3_open("mail.example.com", "username", "password");
$messages = pop3_list($connection);
foreach ($messages as $message) {
$header = pop3_get_header($connection, $message);
$subject = $header["subject"];
$from = $header["from"];
// 其他操作...
}
pop3_close($connection);
require 'PHPMailer/src/PHPMailer.php';
$mail = new PHPMailer\PHPMailer\PHPMailer();
$mail->isPOP3();
$mail->Host = 'mail.example.com';
$mail->Port = 110;
$mail->Username = 'username';
$mail->Password = 'password';
$mail->setFrom('from@example.com');
$mail->addAddress('to@example.com');
if ($mail->connect()) {
$mail->login();
$mails = $mail->listMessages();
foreach ($mails as $mail) {
$subject = $mail->subject;
$from = $mail->from;
// 其他操作...
}
$mail->disconnect();
}
以上是一些常用的讀取郵件的方法,具體使用哪種方法取決于你的需求和環境設置。