/** * Use a fake POP3 server to test POP-before-SMTP auth * With a known-bad login */ public function testPopBeforeSmtpBad() { //Start a fake POP server on a different port //so we don't inadvertently connect to the previous instance $pid = shell_exec('nohup ./runfakepopserver.sh 1101 >/dev/null 2>/dev/null & printf "%u" $!'); $this->pids[] = $pid; sleep(2); //Test a known-bad login $this->assertFalse(POP3::popBeforeSmtp('localhost', 1101, 10, 'user', 'xxx', $this->Mail->SMTPDebug), 'POP before SMTP should have failed'); shell_exec('kill -TERM ' . escapeshellarg($pid)); sleep(2); }
<?php /** * This example shows how to use POP-before-SMTP for authentication. */ require '../PHPMailerAutoload.php'; //Authenticate via POP3. //After this you should be allowed to submit messages over SMTP for a while. //Only applies if your host supports POP-before-SMTP. $pop = POP3::popBeforeSmtp('pop3.example.com', 110, 30, 'username', 'password', 1); //Create a new PHPMailer instance //Passing true to the constructor enables the use of exceptions for error handling $mail = new PHPMailer(true); try { $mail->isSMTP(); //Enable SMTP debugging // 0 = off (for production use) // 1 = client messages // 2 = client and server messages $mail->SMTPDebug = 2; //Ask for HTML-friendly debug output $mail->Debugoutput = 'html'; //Set the hostname of the mail server $mail->Host = "mail.example.com"; //Set the SMTP port number - likely to be 25, 465 or 587 $mail->Port = 25; //Whether to use SMTP authentication $mail->SMTPAuth = false; //Set who the message is to be sent from $mail->setFrom('*****@*****.**', 'First Last'); //Set an alternative reply-to address