0

Checking the mails to my e-mail address with phpmailler, and printing them on my website Is there a way to do it with PHPMailer? Or how can I do

// include necessary files
require_once "PHPMailer/PHPMailer.php";
require_once "PHPMailer/Exception.php";
require_once "PHPMailer/POP3.php";

// set email configurations
$hostname = 'mail.mydomin.com'; // email server address
$username = 'username@mydomin.com'; // email address
$password = 'password'; // email password

// connect to email server
$pop3 = new POP3();
$pop3->connect($hostname);
$pop3->login($username, $password);

// get emails from inbox
$emails = $pop3->getListing();

// print email headers and contents
if($emails) {
foreach($emails as $email_number => $email_header) {
$subject = $email_header->subject;
$from = $email_header->from;
$body = $pop3->getRawListing($email_number);
echo "Subject: ".$subject."<br>";
echo "From: ".$from."<br>";
echo "Body: ".$body."<br>";
}
}

// close the email connection
$pop3->disconnect();

i tried this but it didn't work

ADyson
  • 57,178
  • 14
  • 51
  • 63
  • 1
    Can you give us more details please? When you say 'it didn't work', what happened? Did you see an error? – Rob Eyre Apr 18 '23 at 11:11
  • 1
    PHPMailer can only be used for _sending_ emails, not receiving them. Also, https://phpmailer.github.io/PHPMailer/classes/PHPMailer-PHPMailer-POP3.html explains what the PHPMailer POP3 class is for, and what it can and can't do. I wonder if you've confused it with a different POP3 implementation for PHP - because some of the functions you've tried to call don't exist in the PHPMailer POP3 class (as per those docs) – ADyson Apr 18 '23 at 11:19
  • 2
    Indeed, the PHPMailer POP3 class is not a general purpose POP3 client; it's just for auth. I'd also recommend staying well away from POP3 if you can. POP3 is really outdated and unpleasant to use; IMAP is a far better protocol to use for this. – Synchro Apr 18 '23 at 11:35

0 Answers0