sending mail error

the mail() function

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Mon Apr 02, 2012 5:31 pm

sending mail error

Postby uwak » Mon Apr 02, 2012 5:50 pm


I just bought a book on PHP and tested sample codes including below. Please try to run this and check what the error means. I can't figure why the error. I just copy the php code below from the book. Please help....
If below code will not work, please refer me to A WORKING CODE related to sending email in this forum. My first time here. Tnxs!


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<title>Contact Me</title>
<!--<?php include ("inc_header.html"); ?>
<div style = "width:20%; text-align:center; float:left">
<?php include ("inc_buttonnav.html"); ?>

<!--Start of Dynamic Content section-->
function validateInput($data, $fieldName) {
global $errorCount;
if (empty($data)) {
echo "\"$fieldName\" is a required field.<br/>n";
$retval = "";
} else { //clean the input if not empty.
$retval = trim($data);
$retval = stripslashes($retval);

function validateEmail($data, $fieldName) {
global $errorCount;
if (empty($data)) {
echo "\"$fieldName\" is a required field.<br />\n";
&retval = "";
} else { //clean nput only if it is empty.
$retval = trim($data);
$retval = stripslashes($retval);
$pattern = "/^[\w-]+(\.[\w-]+)*@" .
"[\w-]+(\.[\w-]+)*" .
if (preg_match($pattern, $retval)==0) {
echo "\"$fieldName\" is not a valid e-mail address.<br />\n";

function displayForm($Sender, $Email, $Subject, $Message) {
<h2 style = "text-align:center">Contact Me</h2>
<form name="contact" action="ContactForm.php" method="post">
<p>Your Name: <input type="text" name="Sender" value="<?php echo $Sender; ?>" /></p>
<p>Your E-mail: <input type="text" name="Email" value="<?php echo $Email; ?>" /></p>
<p>Subject: <input type="text" name="Subject" value="<?php echo $Subject; ?>" /></p>
<p>Message:<br />
<textarea name="Message"><?php echo $Message; ?></textarea></p>
<p><input type="reset" value="Clear Form" />&nbsp;
&nbsp;<input type="submit" name="Submit" value="Send Form" /></p>

//initialize vars.
$ShowForm = TRUE;
$errorCount = 0;
$Sender = "";
$Email = "";
$Subject = "";
$Message = "";

//check and validate input.
//Note that $_POST['Email'] is checked with the validateEmail() function instead of validateInput() function.
if (isset($_POST['Submit'])) {
$Sender = validateInput($_POST['Sender'], "uwak"); //Your Name
$Email = validateEmail($_POST['Email'], "");//Your E-mail
$Subject = validateInput($_POST['Subject'], "Subject");
$Message = validateInput($_POST['Message'], "Message");
if ($errorCount==0)
$ShowForm = FALSE;
$ShowForm = TRUE;

//check the value of $ShowForm; if true display; otherwise an e-mail message is sent and a status message is
//displayed. Note that a copy is sent to the sender.

if ($ShowForm == TRUE) {
if($errorCount>0) //if there were errors.
echo "<p>Please re-enter the form information below.</p>\n";
displayForm($Sender, $Email, $Subject, $Message);
else {
$SenderAddress = "$Sender <$Email>";
$Headers = "From: $SenderAddress\nCC; $SenderAddress\n";
//substitute e-mail add with your e-mail add.
$result = mail("", $Subject, $Message, $Headers);
if ($result)
echo "<p>Your message has been sent. Thank you, " . $Sender . ".</p>\n";
echo "<p>There was an error sending your message, " . $Sender . ".</p>\n";

<!--Note: all buttons were all named "content". If text hyperlinks are added, the same name can be used as the name
/value pair, and the same code can process both. If you need more buttons or text hyperlinks, simply use the
name "content" and a different value, and add that value as a case in the switch statement.
<a href="WebTemplate.php?content=Home">Home Page</a>-->

<!--End of Dynamic Content section-->
<!--<?php include ('inc_footer.php'); ?>-->

Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 1 guest