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

Mail Sending Error

the mail() function

Moderators: macek, egami, gesf

Mail Sending Error

Postby nagaraju16 » Thu Feb 09, 2012 12:04 am

Hi Techies,
iam new bie.we are running a HTMl website.i implemented a Contact form and seding an email by using the PHP send email fucntionality.please see below code.

PhP form code:

<?php
$errors = '';
$myemail = 'sample@sample.com';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}

$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];

if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}

if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n Email: $email_address \n Message \n $message";

$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";

mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Contact form handler</title>
</head>

<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>


</body>
</html>

HTML Code


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Contact us</title>
<!-- define some style elements-->
<style>
h1
{
font-family : Arial, Helvetica, sans-serif;
font-size : 16px;
font-weight : bold;
}
label,a
{
font-family : Arial, Helvetica, sans-serif;
font-size : 12px;
}

</style>
<!-- a helper script for vaidating the form-->
<script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>
</head>
</head>

<body>
<h1>Contact us</h1>
<form method="POST" name="contactform" action="contact-form-handler.php">
<p>
<label for='name'>Your Name:</label> <br>
<input type="text" name="name">
</p>
<p>
<label for='email'>Email Address:</label> <br>
<input type="text" name="email"> <br>
</p>
<p>
<label for='message'>Message:</label> <br>
<textarea name="message"></textarea>
</p>
<input type="submit" value="Submit"><br>
</form>

<script language="JavaScript">
// Code for validating the form
// Visit http://www.javascript-coder.com/html-fo ... tion.phtml
// for details
var frmvalidator = new Validator("contactform");
frmvalidator.addValidation("name","req","Please provide your name");
frmvalidator.addValidation("email","req","Please provide your email");
frmvalidator.addValidation("email","email","Please enter a valid email address");
</script>
<!--
Sample code from:
http://www.html-form-guide.com/contact- ... -form.html
-->


</body>
</html>

when i run this code on my server it is given the following error.please see below.

HTTP Error 405.0 - Method Not Allowed
The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.


Error code:{0x80070001

the server is windows server 2008/IIS7.do i need to check that server allows PHP code?if so please let me know what to install and how to check the server is PHP is installed?

please advice.

thanks,
Nagaraju.
nagaraju16
New php-forum User
New php-forum User
 
Posts: 1
Joined: Wed Feb 08, 2012 11:55 pm

Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 0 guests

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

cron