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.png', 'phpmailer_mini.png'); // optional name $mail->addAttachment('images/phpmailer.png', 'phpmailer.png'); // optional name $example_code .= "\n\$mail->addAttachment('images/phpmailer_mini.png'," . "'phpmailer_mini.png'); // optional name"; $example_code .= "\n\$mail->addAttachment('images/phpmailer.png', 'phpmailer.png'); // optional name"; $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}"; 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()); } } } 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="">