Topic: Contact Form

Something I made for users to have to make it easily accessible on the forums to contact the administrator (or set user). This is my first mod, so tell me if there is something that I left out in this post. I am almost 100% positive that I have everything correct.

Step 1:
Copy the following code and save as "contactform.php" in your forum folder. Edit line #34 and enter you email address to be sent to.

<?php

##
##
##        Mod title:  Contact Form
##
##      Mod version:  1.0
##   Works on PunBB:  1.2.15
##     Release date:  2005-04-28
##           Author:  Sam Rusch (pghmyn@gmail.com)
##
##      Description:  Gives users a chance to have a simple and easy contact form on their
##                      forums for all their users.
##
##   Affected files:  functions.php
##
##       Affects DB:  No
##
##            Notes:  Easy to edit yourself, and feel free to edit this. If you would like
##                      to spice up the look of the form, it's up to you. The form is not the
##                      best, but it will do for what it is made for.


define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';

require PUN_ROOT.'lang/'.$pun_user['language'].'/index.php';

$page_title = pun_htmlspecialchars($pun_config['o_board_title']);
define('PUN_ALLOW_INDEX', 1);
require PUN_ROOT.'header.php';

//** What EMail should the message be sent to?
$sendto = "youremailhere";


//** Do not edit below this line, unless you know what you are doing.
if ($_POST['send']) {
    $name = trim($_POST['Name']);
    $email = trim($_POST['email']);
    $topic = trim($_POST['topic']);
    $details = trim($_POST['details']);
    
    $headers = "From: ".$name." at ".$email." \r\n"; 
    $headers.= "Content-Type: text/html; charset=ISO-8859-1 "; 
    $headers .= "MIME-Version: 1.0 "; 

    mail($sendto, "Suggestion/Concern (".$topic.")", $details, $headers);
    
    $confirm = "Your message has been successfully sent! If you entered an email, you may have a reply shortly.<br /><br />";
}

?>

<form method="post" action="">
<div class="blocktable">
    <h2><span>Contact Form</span></h2>
    <div class="box">
        <div class="inbox">
            <table cellspacing="0">
                <tr>
                    <th class="tcl" scope="col">Please fill out the form below to send it in an EMail message:</th>
                </tr>
                <tr>
                    <td>
                        <div class="infldset">
                            <?php
                            if (isset($confirm)) {
                                echo $confirm;
                            }                        
                            ?>
                            <b>Your Name</b> (required) <input type="text" name="Name" size="30" /><br />
                            <b>Your EMail</b> <input type="text" name="email" size="30" /><br />
                            <b>Suggestion/Concern</b> (required) <input type="text" name="topic" size="35" /><br /><br />
                            <b>Details</b> (required)<br /><textarea rows="4" cols="60" name="details"></textarea><br />
                            <input type="submit" name="send" value="Send Now!" />
                        </div
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>
</form>

<?php

$footer_style = 'index';
require PUN_ROOT.'footer.php';

Step 2:
Look for the functions.php file in the include folder. Search for the function "function generate_navlinks()" on line 291. The first few lines are what you edit, and they should like like this when you are done:

function generate_navlinks()
{
    global $pun_config, $lang_common, $pun_user;

    // Index and Userlist should always be displayed
    $links[] = '<li id="navindex"><a href="index.php">'.$lang_common['Index'].'</a>';
    $links[] = '<li id="navuserlist"><a href="userlist.php">'.$lang_common['User list'].'</a>';
    $links[] = '<li id="navlogin"><a href="contactform.php">Contact Form</a>';

Step 3:
You are finished and ready to have the contact form working!

Without programming, I would have nothing to do...nahhhh

Re: Contact Form

A couple things about this mod:

1. It's vulnerable to an email injection
http://www.securephpwiki.com/index.php/Email_Injection
http://en.wikipedia.org/wiki/E-mail_injection

2. Step 2 is unnecessary: the administrator simply has to go to Admin Options and add the link as an Additional Navlink

3. You could potentially have 2 divs with the same ID with your suggestion, which would be improper HTML

4. Why not have $sendto be the webmaster or administrator emails listed in Admin Options?

5. Why not use the pun_mail function, which uses the forum settings for mailing (SMTP/mail function)?

Re: Contact Form

Ah, I see. Looks as though I have a lot of work to do on this stuff smile

I hope to get up there, and understand the PunBB structure more thoroughly. If you wouldn't mind, would I be able to contact you in any other way besides on the forums?

Without programming, I would have nothing to do...nahhhh

Re: Contact Form

Sure: send me an email or find me in #punbb on Quakenet smile

Re: Contact Form

Is there any more advanced contact form out there. I mean with spamprotection and foreces fields, example: you have to write a topic.

6 (edited by MattF 2007-11-14 17:32)

Re: Contact Form

http://punbb.org/forums/viewtopic.php?id=17037

The last one on that thread is the most upto date version.

Re: Contact Form

demo of what mattf did is here http://punlancer.com/contact.php

and now it is in the register.php with some tweaks from the team...

My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!