How do I make a feedback form?

  • Thread starter Thread starter Ken
  • Start date Start date
Thanks a lot guys :)
Trigger said:
You could do it purely in HTML with the mailto: command- would be a tad messy but functional:

snip

:)
I copied and pasted this into notepad and uploaded the htm file to my webspace and tested it out. When I hit "Send Feedback" it opened up my Mozilla Thunderbird... :confused:

I'm under the impression that whoever sends feedback will do it solely using the form without his/her email client launching?

Thanks again.
 
Just found this...

http://www.englib.cornell.edu/instruction/www/email-forms-class.html

...and it looks like I need a CGI script which my webspace also doesn't support! :(
Eclipse said:
Will not support your own server side scripts, should you need to run your own scripts on the server, such as PHP, CGI, ASP, etc, you will need to go for a Domain Hosting package.
Think I might go signup for some webspace with Register1. :)
 
OK, I've copied and pasted the following into notepad naming it mail.php - Thanks Rob. :)
Code:
<?php

// CONFIG
$mail_to = 'myemailaddress';
// END CONFIG

session_start();

function strip_mail_headers_single( $string ) {
    return preg_replace('/(%0A|%0D|\\n+|\\r+)/i', '', $string);
}

function strip_mail_headers_multi( $string ) {
    return preg_replace('/(%0A|%0D|\\n+|\\r+)(content-type:|to:|cc:|bcc:)/i', '', $string);
}

function is_valid_email( $string ) {
    return preg_match('^[\_]*([a-z0-9]+(\.|\_*)?)+@([a-z][a-z0-9\-]+(\.|\-*\.))+[a-z]{2,6}$', $string);
}

function send_mail($to, $from, $from_mail, $subject, $message) {
    if ( empty($from) || empty($from_mail) || empty($subject) || empty($message) ) {
        return -1;
    }

    if ( $_SESSION['last_mailed'] + 180 < time() )
        return -2;

    if ( !is_valid_email($from_mail) )
        return -3;

    $from = strip_mail_headers_single($from);
    $from_mail = strip_mail_headers_single($from_mail);
    $subject = strip_mail_headers_single($subject);
    $message = strip_mail_headers_multi($message);

    $_SESSION['last_mailed'] = time();

    return mail($to, $subject, $message, "From: $from <$from_mail>\r\n");
}

if ( !empty($_POST) ) {
    $result = send_mail($mail_to, $_POST['from'], $_POST['from_mail'], $_POST['subject'], $_POST['message']);

    if ( $result == -1 ) {
        echo "<p>Whoops! You need to complete all the fields.</p>";
    } elseif ( $result == -2 ) {
        echo "<p>Whoah, slow down there cowboy! You can only send one mail every three minutes.</p>";
    } elseif ( $result == -3 ) {
        echo "<p>Please enter a valid email address.</p>";
    } else {
        echo "<p>Mail sent successfully!</p>";
    }
}

?>
I've copied and pasted the following on one of my webpages that is in the same directory as mail.php
Code:
<form method="post" action="mail.php">

    <p><label for="from">Your name:</label></p>
    <p><input type="text" name="from" id="from" /></p>

    <p><label for="from_mail">Your email address:</label></p>
    <p><input type="text" name="from_mail" id="from_mail" /></p>

    <p><label for="subject">Subject:</label></p>
    <p><input type="text" name="subject" id="subject" /></p>

    <p><label for="message">Message:</label></p>
    <p><textarea name="message" id="message"></textarea></p>

    <p><input type="submit" value="Send Message" /></p>

</form>

But when I test it, I don't get an email in my inbox.

Any ideas?

Cheers.
 
Hmmm, now I'm getting...

"Whoah, slow down there cowboy! You can only send one mail every three minutes."
 
I understand what each line of the above code is doing but as for each individual character of the code, well I thought I'd post it so thanks for checking it through Joe. :)

I've given it more than 3 minutes a few times and it still doesn't work. I'll try again when I get back home.
Yep, I've recently bought a domain and webspace from Register1 as I wanted php support. I did try another piece of feedback form code I found online (it worked) but I wasn't sure if it would be secure from spam and whatever else and robmiller seems a regular in this section and proficient at this sort of thing.
 
Back
Top Bottom