CharSet = 'utf-8'; $mail->Debugoutput = $CFG['smtp_debugoutput']; $example_code .= "\n\n\$mail = new PHPMailer(true);"; $example_code .= "\n\$mail->CharSet = 'utf-8';"; class phpmailerAppException extends phpmailerException {} $example_code .= "\n\nclass phpmailerAppException extends phpmailerException {}"; $example_code .= "\n\ntry {"; try { if ( isset($_POST["submit"]) && $_POST['submit'] == "Submit" ) { $to = $_POST['To_Email']; if (!PHPMailer::ValidateAddress($to)) { throw new phpmailerAppException("Email address " . $to . " is invalid -- aborting!"); } $example_code .= "\n\$to = '{$_POST['To_Email']}';"; $example_code .= "\nif(!PHPMailer::ValidateAddress(\$to)) {"; $example_code .= "\n throw new phpmailerAppException(\"Email address \" . \$to . \" is invalid -- aborting!\");"; $example_code .= "\n}"; switch ($_POST['test_type']) { case 'smtp': $mail->IsSMTP(); // telling the class to use SMTP $mail->SMTPDebug = (integer)$_POST['smtp_debug']; $mail->Host = $_POST['smtp_server']; // SMTP server $mail->Port = (integer)$_POST['smtp_port']; // set the SMTP port if ($_POST['smtp_secure']) { $mail->SMTPSecure = strtolower($_POST['smtp_secure']); } $mail->SMTPAuth = array_key_exists('smtp_authenticate', $_POST); // enable SMTP authentication? if (array_key_exists('smtp_authenticate', $_POST)) { $mail->Username = $_POST['authenticate_username']; // SMTP account username $mail->Password = $_POST['authenticate_password']; // SMTP account password } $example_code .= "\n\$mail->IsSMTP();"; $example_code .= "\n\$mail->SMTPDebug = ".$_POST['smtp_debug'].";"; $example_code .= "\n\$mail->Host = \"".$_POST['smtp_server']."\";"; $example_code .= "\n\$mail->Port = \"".$_POST['smtp_port']."\";"; $example_code .= "\n\$mail->SMTPSecure = \"".strtolower($_POST['smtp_secure'])."\";"; $example_code .= "\n\$mail->SMTPAuth = ".(array_key_exists('smtp_authenticate', $_POST)?'true':'false').";"; if (array_key_exists('smtp_authenticate', $_POST)) { $example_code .= "\n\$mail->Username = \"".$_POST['authenticate_username']."\";"; $example_code .= "\n\$mail->Password = \"".$_POST['authenticate_password']."\";"; } break; case 'mail': $mail->IsMail(); // telling the class to use PHP's Mail() $example_code .= "\n\$mail->IsMail();"; break; case 'sendmail': $mail->IsSendmail(); // telling the class to use Sendmail $example_code .= "\n\$mail->IsSendmail();"; break; case 'qmail': $mail->IsQmail(); // telling the class to use Qmail $example_code .= "\n\$mail->IsQmail();"; break; default: throw new phpmailerAppException('Invalid test_type provided'); } try { if ( $_POST['From_Name'] != '' ) { $mail->AddReplyTo($_POST['From_Email'], $_POST['From_Name']); $mail->From = $_POST['From_Email']; $mail->FromName = $_POST['From_Name']; $example_code .= "\n\$mail->AddReplyTo(\"".$_POST['From_Email']."\", \"".$_POST['From_Name']."\");"; $example_code .= "\n\$mail->From = \"".$_POST['From_Email']."\";"; $example_code .= "\n\$mail->FromName = \"".$_POST['From_Name']."\";"; } else { $mail->AddReplyTo($_POST['From_Email']); $mail->From = $_POST['From_Email']; $mail->FromName = $_POST['From_Email']; $example_code .= "\n\$mail->AddReplyTo(\"".$_POST['From_Email']."\");"; $example_code .= "\n\$mail->From = \"".$_POST['From_Email']."\";"; $example_code .= "\n\$mail->FromName = \"".$_POST['From_Email']."\";"; } if ( $_POST['To_Name'] != '' ) { $mail->AddAddress($to, $_POST['To_Name']); $example_code .= "\n\$mail->AddAddress(\"$to\", \"".$_POST['To_Name']."\");"; } else { $mail->AddAddress($to); $example_code .= "\n\$mail->AddAddress(\"$to\");"; } if ( $_POST['bcc_Email'] != '' ) { $indiBCC = explode(" ", $_POST['bcc_Email']); foreach ($indiBCC as $key => $value) { $mail->AddBCC($value); $example_code .= "\n\$mail->AddBCC(\"$value\");"; } } if ( $_POST['cc_Email'] != '' ) { $indiCC = explode(" ", $_POST['cc_Email']); foreach ($indiCC as $key => $value) { $mail->AddCC($value); $example_code .= "\n\$mail->AddCC(\"$value\");"; } } } catch (phpmailerException $e) { //Catch all kinds of bad addressing throw new phpmailerAppException($e->getMessage()); } $mail->Subject = $_POST['Subject'] . ' (PHPMailer test using ' . strtoupper($_POST['test_type']) . ')'; $example_code .= "\n\$mail->Subject = \"".$_POST['Subject'].'(PHPMailer test using ' . strtoupper($_POST['test_type']) . ')";'; if ( $_POST['Message'] == '' ) { $body = file_get_contents('contents.html'); } else { $body = $_POST['Message']; } $example_code .= "\n\$body = <<<'EOT'\n".htmlentities($body)."\nEOT;"; $mail->WordWrap = 80; // set word wrap $mail->MsgHTML($body, dirname(__FILE__), true); //Create message bodies and embed images $example_code .= "\n\$mail->WordWrap = 80;"; $example_code .= "\n\$mail->MsgHTML(\$body, dirname(__FILE__), true); //Create message bodies and embed images"; $mail->AddAttachment('images/phpmailer-mini.gif', 'phpmailer-mini.gif'); // optional name $mail->AddAttachment('images/phpmailer.png', 'phpmailer.png'); // optional name $example_code .= "\n\$mail->AddAttachment('images/phpmailer-mini.gif', 'phpmailer-mini.gif'); // optional name"; $example_code .= "\n\$mail->AddAttachment('images/phpmailer.png', 'phpmailer.png'); // optional name"; try { $mail->Send(); $results_messages[] = "Message has been sent using " . strtoupper($_POST["test_type"]); } catch (phpmailerException $e) { throw new phpmailerAppException("Unable to send to: " . $to. ': '.$e->getMessage()); } $example_code .= "\n\ntry {"; $example_code .= "\n \$mail->Send();"; $example_code .= "\n \$results_messages[] = \"Message has been sent using ". strtoupper($_POST['test_type'])."\";"; $example_code .= "\n}"; $example_code .= "\ncatch (phpmailerException \$e) {"; $example_code .= "\n throw new phpmailerAppException('Unable to send to: ' . \$to. ': '.\$e->getMessage());"; $example_code .= "\n}"; } } catch (phpmailerAppException $e) { $results_messages[] = $e->errorMessage(); } $example_code .= "\n}"; $example_code .= "\ncatch (phpmailerAppException \$e) {"; $example_code .= "\n \$results_messages[] = \$e->errorMessage();"; $example_code .= "\n}"; $example_code .= "\n\nif (count(\$results_messages) > 0) {"; $example_code .= "\n echo \"

Run results

\\n\";"; $example_code .= "\n echo \"\\n\";"; $example_code .= "\n}"; ?> PHPMailer Test Page "; echo exit("ERROR: Wrong PHP version. Must be PHP 5 or above."); } if (count($results_messages) > 0) { echo '

Run results

'; echo ''; } if (isset($_POST["submit"]) && $_POST["submit"] == "Submit") { echo "
\n"; echo "
Script:\n"; echo "
\n";
        echo $example_code;
        echo "\n
\n"; echo "\n
\n"; } ?>
Mail Details
Test will include two attachments.
Mail Test Specs
Test Type
required>
required>
required>
required>
"> SMTP Specific Options:
value="">