📄 phpmailer_test.php
字号:
function test_Low_Priority() { $this->Mail->Priority = 5; $this->Mail->Body = "Here is the main body. There should be " . "a reply to address in this message."; $this->Mail->Subject .= ": Low Priority"; $this->Mail->AddReplyTo("nobody@nobody.com", "Nobody (Unit Test)"); $this->BuildBody(); $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); } /** * Simple plain file attachment test. */ function test_Multiple_Plain_FileAttachment() { $this->Mail->Body = "Here is the text body"; $this->Mail->Subject .= ": Plain + Multiple FileAttachments"; if(!$this->Mail->AddAttachment("rocks.png")) { $this->assert(false, $this->Mail->ErrorInfo); return; } if(!$this->Mail->AddAttachment("phpmailer_test.php", "test.txt")) { $this->assert(false, $this->Mail->ErrorInfo); return; } $this->BuildBody(); $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); } /** * Simple plain string attachment test. */ function test_Plain_StringAttachment() { $this->Mail->Body = "Here is the text body"; $this->Mail->Subject .= ": Plain + StringAttachment"; $sAttachment = "These characters are the content of the " . "string attachment.\nThis might be taken from a ". "database or some other such thing. "; $this->Mail->AddStringAttachment($sAttachment, "string_attach.txt"); $this->BuildBody(); $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); } /** * Plain quoted-printable message. */ function test_Quoted_Printable() { $this->Mail->Body = "Here is the main body"; $this->Mail->Subject .= ": Plain + Quoted-printable"; $this->Mail->Encoding = "quoted-printable"; $this->BuildBody(); $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); } /** * Try a plain message. */ function test_Html() { $this->Mail->IsHTML(true); $this->Mail->Subject .= ": HTML only"; $this->Mail->Body = "This is a <b>test message</b> written in HTML. </br>" . "Go to <a href=\"http://phpmailer.sourceforge.net/\">" . "http://phpmailer.sourceforge.net/</a> for new versions of " . "phpmailer. <p/> Thank you!"; $this->BuildBody(); $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); } /** * Simple HTML and attachment test */ function test_HTML_Attachment() { $this->Mail->Body = "This is the <b>HTML</b> part of the email."; $this->Mail->Subject .= ": HTML + Attachment"; $this->Mail->IsHTML(true); if(!$this->Mail->AddAttachment("phpmailer_test.php", "test_attach.txt")) { $this->assert(false, $this->Mail->ErrorInfo); return; } $this->BuildBody(); $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); } /** * An embedded attachment test. */ function test_Embedded_Image() { $this->Mail->Body = "Embedded Image: <img alt=\"phpmailer\" src=\"cid:my-attach\">" . "Here is an image!</a>"; $this->Mail->Subject .= ": Embedded Image"; $this->Mail->IsHTML(true); if(!$this->Mail->AddEmbeddedImage("rocks.png", "my-attach", "rocks.png", "base64", "image/png")) { $this->assert(false, $this->Mail->ErrorInfo); return; } $this->BuildBody(); $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); } /** * An embedded attachment test. */ function test_Multi_Embedded_Image() { $this->Mail->Body = "Embedded Image: <img alt=\"phpmailer\" src=\"cid:my-attach\">" . "Here is an image!</a>"; $this->Mail->Subject .= ": Embedded Image + Attachment"; $this->Mail->IsHTML(true); if(!$this->Mail->AddEmbeddedImage("rocks.png", "my-attach", "rocks.png", "base64", "image/png")) { $this->assert(false, $this->Mail->ErrorInfo); return; } if(!$this->Mail->AddAttachment("phpmailer_test.php", "test.txt")) { $this->assert(false, $this->Mail->ErrorInfo); return; } $this->BuildBody(); $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); } /** * Simple multipart/alternative test. */ function test_AltBody() { $this->Mail->Body = "This is the <b>HTML</b> part of the email."; $this->Mail->AltBody = "Here is the text body of this message. " . "It should be quite a few lines. It should be wrapped at the " . "40 characters. Make sure that it is."; $this->Mail->WordWrap = 40; $this->AddNote("This is a mulipart alternative email"); $this->Mail->Subject .= ": AltBody + Word Wrap"; $this->BuildBody(); $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); } /** * Simple HTML and attachment test */ function test_AltBody_Attachment() { $this->Mail->Body = "This is the <b>HTML</b> part of the email."; $this->Mail->AltBody = "This is the text part of the email."; $this->Mail->Subject .= ": AltBody + Attachment"; $this->Mail->IsHTML(true); if(!$this->Mail->AddAttachment("phpmailer_test.php", "test_attach.txt")) { $this->assert(false, $this->Mail->ErrorInfo); return; } $this->BuildBody(); $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); $fp = fopen("message.txt", "w"); fwrite($fp, $this->Mail->CreateHeader() . $this->Mail->CreateBody()); fclose($fp); } function test_MultipleSend() { $this->Mail->Body = "Sending two messages without keepalive"; $this->BuildBody(); $subject = $this->Mail->Subject; $this->Mail->Subject = $subject . ": SMTP 1"; $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); $this->Mail->Subject = $subject . ": SMTP 2"; $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); } function test_SmtpKeepAlive() { $this->Mail->Body = "This was done using the SMTP keep-alive."; $this->BuildBody(); $subject = $this->Mail->Subject; $this->Mail->SMTPKeepAlive = true; $this->Mail->Subject = $subject . ": SMTP keep-alive 1"; $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); $this->Mail->Subject = $subject . ": SMTP keep-alive 2"; $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); $this->Mail->SmtpClose(); } function test_Error() { $this->Mail->Subject .= ": This should be sent"; $this->BuildBody(); $this->Mail->ClearAllRecipients(); // no addresses should cause an error $this->assert($this->Mail->IsError() == false, "Error found"); $this->assert($this->Mail->Send() == false, "Send succeeded"); $this->assert($this->Mail->IsError(), "No error found"); $this->assertEquals('You must provide at least one ' . 'recipient email address.', $this->Mail->ErrorInfo); $this->Mail->AddAddress(get("mail_to")); $this->assert($this->Mail->Send(), "Send failed"); }} /** * Create and run test instance. */ if(isset($HTTP_GET_VARS)) $global_vars = $HTTP_GET_VARS;else $global_vars = $_REQUEST;if(isset($global_vars["submitted"])){ echo "Test results:<br>"; $suite = new TestSuite( "phpmailerTest" ); $testRunner = new TestRunner; $testRunner->run($suite); echo "<hr noshade/>";}function get($sName) { global $global_vars; if(isset($global_vars[$sName])) return $global_vars[$sName]; else return "";}?><html><body><h3>phpmailer Unit Test</h3>By entering a SMTP hostname it will automatically perform tests with SMTP.<form name="phpmailer_unit" action="phpmailer_test.php" method="get"><input type="hidden" name="submitted" value="1"/>To Address: <input type="text" size="50" name="mail_to" value="<?php echo get("mail_to"); ?>"/><br/>Cc Address: <input type="text" size="50" name="mail_cc" value="<?php echo get("mail_cc"); ?>"/><br/>SMTP Hostname: <input type="text" size="50" name="mail_host" value="<?php echo get("mail_host"); ?>"/><p/><input type="submit" value="Run Test"/></form></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -