Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

sending mail error

the mail() function

Moderators: macek, egami, gesf

sending mail error

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

Greetings!

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!

Uwak
//------------------------------------------------------------------------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Contact Me</title>
</head>
<body>
<!--<?php include ("inc_header.html"); ?>
<div style = "width:20%; text-align:center; float:left">
<?php include ("inc_buttonnav.html"); ?>
</div>-->

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

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

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>
</form>
<?php
}

//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'], "uwakwakwak@yahoo.com");//Your E-mail
$Subject = validateInput($_POST['Subject'], "Subject");
$Message = validateInput($_POST['Message'], "Message");
if ($errorCount==0)
$ShowForm = FALSE;
else
$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("uwakwakwak@yahoo.com", $Subject, $Message, $Headers);
if ($result)
echo "<p>Your message has been sent. Thank you, " . $Sender . ".</p>\n";
else
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'); ?>-->
</body>
</html>
//------------------------------------------------------------------------------------
uwak
New php-forum User
New php-forum User
 
Posts: 1
Joined: Mon Apr 02, 2012 5:31 pm

Return to PHP coding => Mail

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.