TESTING THE PHP MAIL() AND MAILARAY() FUNCTIONS - Aug 23rd, 2014
|
Here are 2 simple scripts for testing your server's PHP mail() and one to test CMSB's built in mailArray function:
CAVEAT: Make sure that the 'from' address and the 'to' address are real, or your mailserver may kick your email back with no specific error messages. I had a .com instead of a .org as the TLD in an admin email address, and since there was no .com domain, the password change email, supposedly coming from the admin email address, was kicked back by the server as invalid and never got delivered. I guess that applies to those noreply@noreply.com email return addresses as well.
<?php $message = '';
if (isset($_POST['email']) && !empty($_POST['email'])){ if (mail($_POST['email'], $_POST['subject'], $_POST['body'], '')){ $message = "Email has been sent to <b>".$_POST['email']."</b>."; }else{ $message = "Failed sending message to <b>".$_POST['email']."</b>."; } }else{ if (isset($_POST['submit'])){ $message = "No email address specified!"; } }
if (!empty($message)){ $message .= "n"; } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title> Mail test 3 </title> </head> <body> <?php echo $message; ?> <form method="post" action=""> <table> <tr> <td> e-mail </td> <td> <input name="email" value="<?php if (isset($_POST['email']) && !empty($_POST['email'])) echo $_POST['email']; ?>"> </td> </tr> <tr> <td> subject </td> <td> <input name="subject"> </td> </tr> <tr> <td> message </td> <td> <textarea name="body"></textarea> </td> </tr> <tr> <td> </td> <td> <input type="submit" value="send" name="submit"> </td> </tr> </table> </form> </body> </html>
<?php if ( function_exists( 'mail' ) ) { echo 'mail() is available'; } else { echo 'mail() has been disabled'; } ?> <?php
$msg=""; if(isset($_POST['submit'])) {
$from_add = "someone@a_real_domain.com";
$to_add = "you@your_domain.com"; //<-- put your email address here
$subject = "Test Subject"; $message = "Test Message 4"; $headers = "From: $from_add \r\n"; $headers .= "Reply-To: $from_add \r\n"; $headers .= "Return-Path: $from_add\r\n"; $headers .= "X-Mailer: PHP \r\n"; if(mail($to_add,$subject,$message,$headers)) { $msg = "Mail sent OK"; } else { $msg = "Error sending email!"; } } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Test form to email</title> </head>
<body> <?php echo $msg ?> <p> <form action='<?php echo htmlentities($_SERVER['PHP_SELF']); ?>' method='post'> <input type='submit' name='submit' value='Submit'> </form> </p>
</body> </html>
<?php // load viewer library $libraryPath = 'cmsAdmin/lib/viewer_functions.php'; $dirsToCheck = array('','../','../../','../../../','../../../../'); foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }} if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>mailArray test2</title> </head>
<body>
<?php $message = 'This is a test message'; $mailArray = array( 'to' => 'you@your_domain.com', 'from' => 'someone@a_real_domain.com', 'subject' => 'mailarray test 2', 'html' => $message ); $errors = sendMessage($mailArray); ?>
</body> </html>
|
The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact
Interactive Tools for information on the downloading of the software or the purchasing of licenses.