CharSet = 'utf-8'; ini_set('default_charset', 'UTF-8'); $mail->Debugoutput = $CFG['smtp_debugoutput']; $example_code .= "\n\n\$mail = new PHPMailer(true);"; $example_code .= "\n\$mail->CharSet = 'utf-8';"; $example_code .= "\nini_set('default_charset', 'UTF-8');"; class phpmailerAppException extends phpmailerException { } $example_code .= "\n\nclass phpmailerAppException extends phpmailerException {}"; $example_code .= "\n\ntry {"; // Convert a string to its JavaScript representation. function JSString($s) { static $from = array("\\", "/", "\n", "\t", "\r", "\b", "\f", '"'); static $to = array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\\"'); return is_null($s)? 'null': '"' . str_replace($from, $to, "$s") . '"'; } try { if (isset($_POST["submit"]) && $_POST['submit'] == "Submit") { $to = $to_email; if (!PHPMailer::validateAddress($to)) { throw new phpmailerAppException("Email address " . $to . " is invalid -- aborting!"); } $example_code .= "\n\$to = '" . addslashes($to_email) . "';"; $example_code .= "\nif(!PHPMailer::validateAddress(\$to)) {"; $example_code .= "\n throw new phpmailerAppException(\"Email address \" . " . "\$to . \" is invalid -- aborting!\");"; $example_code .= "\n}"; switch ($test_type) { case 'smtp': $mail->isSMTP(); // telling the class to use SMTP $mail->SMTPDebug = (integer)$smtp_debug; $mail->Host = $smtp_server; // SMTP server $mail->Port = (integer)$smtp_port; // set the SMTP port if ($smtp_secure) { $mail->SMTPSecure = strtolower($smtp_secure); } $mail->SMTPAuth = array_key_exists('smtp_authenticate', $_POST); // enable SMTP authentication? if (array_key_exists('smtp_authenticate', $_POST)) { $mail->Username = $authenticate_username; // SMTP account username $mail->Password = $authenticate_password; // SMTP account password } $example_code .= "\n\$mail->isSMTP();"; $example_code .= "\n\$mail->SMTPDebug = " . (integer) $smtp_debug . ";"; $example_code .= "\n\$mail->Host = \"" . addslashes($smtp_server) . "\";"; $example_code .= "\n\$mail->Port = \"" . addslashes($smtp_port) . "\";"; $example_code .= "\n\$mail->SMTPSecure = \"" . addslashes(strtolower($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 = \"" . addslashes($authenticate_username) . "\";"; $example_code .= "\n\$mail->Password = \"" . addslashes($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($from_email, $from_name); $mail->setFrom($from_email, $from_name); $example_code .= "\n\$mail->addReplyTo(\"" . addslashes($from_email) . "\", \"" . addslashes($from_name) . "\");"; $example_code .= "\n\$mail->setFrom(\"" . addslashes($from_email) . "\", \"" . addslashes($from_name) . "\");"; } else { $mail->addReplyTo($from_email); $mail->setFrom($from_email, $from_email); $example_code .= "\n\$mail->addReplyTo(\"" . addslashes($from_email) . "\");"; $example_code .= "\n\$mail->setFrom(\"" . addslashes($from_email) . "\", \"" . addslashes($from_email) . "\");"; } if ($_POST['To_Name'] != '') { $mail->addAddress($to, $to_name); $example_code .= "\n\$mail->addAddress(\"$to\", \"" . addslashes($to_name) . "\");"; } else { $mail->addAddress($to); $example_code .= "\n\$mail->addAddress(\"$to\");"; } if ($_POST['bcc_Email'] != '') { $indiBCC = explode(" ", $bcc_email); foreach ($indiBCC as $key => $value) { $mail->addBCC($value); $example_code .= "\n\$mail->addBCC(\"" . addslashes($value) . "\");"; } } if ($_POST['cc_Email'] != '') { $indiCC = explode(" ", $cc_Email); foreach ($indiCC as $key => $value) { $mail->addCC($value); $example_code .= "\n\$mail->addCC(\"" . addslashes($value) . "\");"; } } } catch (phpmailerException $e) { //Catch all kinds of bad addressing throw new phpmailerAppException($e->getMessage()); } $mail->Subject = $subject . ' (PHPMailer test using ' . strtoupper($test_type) . ')'; $example_code .= "\n\$mail->Subject = \"" . addslashes($subject) . ' (PHPMailer test using ' . addslashes(strtoupper($test_type)) . ')";'; if ($_POST['Message'] == '') { $body = file_get_contents('contents.html'); } else { $body = $message; } $example_code .= "\n\$body = <<<'EOT'\n$body\nEOT;"; $mail->WordWrap = 78; // set word wrap to the RFC2822 limit $mail->msgHTML($body, dirname(__FILE__), true); //Create message bodies and embed images $example_code .= "\n\$mail->WordWrap = 78;"; $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 " . addslashes(strtoupper($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($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 htmlentities($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="true">