email

Hi there,

I am a complete beginner to php and am currently trying to set up a contact form

Here is my contact form:

[php]

Name
<div class="holder">
    <label>E-Mail</label>
    <input type="text" value="" name="email" class="textbox" />
</div>
                                
<div class="holder">
    <label>Subject</label>
    <input type="text" value="" name="subject" class="textbox" />
</div>
                                
<div class="holder">
    <label>Message</label>
    <textarea cols="25" rows="5" name="message" class="textbox"></textarea>
</div>
                                
<div class="holder">
    <input type="submit" value="Send Message" name="submit" class="submit" />
</div>
[/php]

Here is emailform.php

[php]

<?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "[email protected]"; $email_subject = "New e-mail subscriber"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form your submitted. "; echo "These errors appear below.

"; echo $error."

"; echo "Please go back and fix these errors.

"; die(); } // validation expected data exists if (!isset($_POST['email'])) { died('We are sorry, but there appears to be a problem with the email your submitted.'); } $email_from = $_POST['email']; // required $error_message = ""; $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"; if(!eregi($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.
'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Email: ".clean_string($email_from)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?>

Thank you for contacting us. We will be in touch with you very soon.

<? } ?>

[/php]

Here is contact-action.php

[php]

<?php /* Credits: Bit Repository URL: http://www.bitrepository.com/ */ include 'config.php'; error_reporting (E_ALL ^ E_NOTICE); $post = (!empty($_POST)) ? true : false; if($post) { include 'functions.php'; $name = stripslashes($_POST['name']); $email = trim($_POST['email']); $subject = stripslashes($_POST['subject']); $message = stripslashes($_POST['message']); $error = ''; // Check name if(!$name) { $error .= 'Please enter your name.
'; } // Check email if(!$email) { $error .= 'Please enter an e-mail address.
'; } if($email && !ValidateEmail($email)) { $error .= 'Please enter a valid e-mail address.
'; } // Check message (length) if(!$message || strlen($message) < 15) { $error .= "Please enter your message. It should have at least 15 characters.
"; } if(!$error) { $mail = mail(WEBMASTER_EMAIL, $subject, $message, "From: ".$name." <".$email.">\r\n" ."Reply-To: ".$email."\r\n" ."X-Mailer: PHP/" . phpversion()); if($mail) { echo 'OK'; } } else { echo '
'.$error.'
'; } } ?>

[/php]

here is the config.php

[php]

<?php // To define("WEBMASTER_EMAIL", '[email protected]'); ?>

[/php]

and then functions.php

[php]

<?php function ValidateEmail($email) { /* (Name) Letters, Numbers, Dots, Hyphens and Underscores (@ sign) (Domain) (with possible subdomain(s) ). Contains only letters, numbers, dots and hyphens (up to 255 characters) (. sign) (Extension) Letters only (up to 10 (can be increased in the future) characters) */ $regex = '/([a-z0-9_.-]+)'. # name '@'. # at '([a-z0-9.-]+){2,255}'. # domain & possibly subdomains '.'. # period '([a-z]+){2,10}/i'; # domain extension if($email == '') { return false; } else { $eregi = preg_replace($regex, '', $email); } return empty($eregi) ? true : false; } ?>

[/php]

I have no idea what I am doing wrong. Any help much appreciated.

Thank you

If you don’t specify a method on your form tag the default is GET (which would be $_GET not $_POST)

Add a method to your form tag.

Sponsor our Newsletter | Privacy Policy | Terms of Service