Contact Form

Status
Not open for further replies.

bucks

New Member
Hey all.

Im sure most of ye will be able to answer this in yer sleep so here goes,

How do i go about getting information filled out on a contact form sent to my email address ? I had a look at formmail but i drew a blank...

Here is the code for the form that im using ;

PHP:
<form id="myform" class="cssform" action="">

<p>
<label for="user">Name:</label>
<input type="text" id="user" value="" />
</p>

<p>
<label for="phone">Phone:</label>
<input type="text" id="phone" value="" />
</p>


<p>
<label for="emailaddress">Email Address:</label>
<input type="text" id="emailaddress" value="" />
</p>

<p>
<label for="comments">Query:</label>
<textarea id="comments" rows="5" cols="25"></textarea>
</p>

<div style="margin-left: 150px;">
<input type="submit" value="Submit" /> <input type="reset" value="Reset" />
</div>

</form>
 

louie

New Member
can you run php code or asp code on your website hosting account?
 

daviddoran

New Member
Code:
<?php
if( isset($_POST['user']) && isset($_POST['emailaddress']) )
{
        $to = "youremail@yourdomain.com";
        $comments = (( isset($_POST['comments']) )?($_POST['comments']):(false));
        if( $comments!=False )
        {
                $subject = 'Query about: ' . substr($comments,0,10).'...';
                $name = (( isset($_POST['user']) )?($_POST['user']):('N/A'));
                $phone = (( isset($_POST['phone']) )?($_POST['phone']):('N/A'));
                $email = (( isset($_POST['emailaddress']) )?($_POST['emailaddress']):('N/A'));
                $message =
                'Name : '.$name."\n"
                .'Phone : '.$phone."\n"
                .'Email Address : '.$email."\n"."\n"
                .'Query : '.$comments."\n"."\n"
                .'From IP: '.(( isset($_SERVER['IP_ADDR']) )?($_SERVER['IP_ADDR']):('N/A'));
                $mail_result = @ mail( $to, $subject, $message );
                echo $message;
                if( $mail_result )
                {
                        echo 'Thank you for your query.';
                }
                else{ echo 'Unfortunately your query could not be received at this time, please try again later.'; }
        }
        else{ echo 'Sorry, you must enter a query.'; }
}
else
{
?>

<form id="myform" class="cssform" action="" method="post">
 <p>
    <label for="user">Name:</label>
    <input type="text" id="user" name="user" value="" />
 </p>

 <p>
    <label for="phone">Phone:</label>
    <input type="text" id="phone" name="phone" value="" />
 </p>

 <p>
    <label for="emailaddress">Email Address:</label>
    <input type="text" id="emailaddress" name="emailaddress" value="" />
 </p>

 <p>
    <label for="comments">Query:</label>
    <textarea id="comments" name="comments" rows="5" cols="25"></textarea>
 </p>

 <div style="margin-left: 150px;">
    <input type="submit" value="Submit" />
    <input type="reset" value="Reset" />
 </div>
</form>

<?php
}
?>
Is what you're looking for I believe.

And an example of the email your will receive:
Code:
Name : John Doe
Phone : 484839
Email Address : johndoe@gmail.com

Query : I want to know.

From IP: 221.243.24.13

You can change the error messages and the $to variable to your email address.
 

kae

New Member
first off - you need to use "name" as well as "id" in your inputs.

secondly - here's a drop-in replacement for formmail written in PHP: http://verens.com/files/formmail.tbz2
- you write your form as if you were going to send it to /cgi-bin/formmail.cgi, but instead, change the form "action" to point to the formmail.php in the archive. It also insists on a captcha, meaning that spambots won't use your mailer as a relay (sorry David - yours is wide open).
 

mneylon

Administrator
Staff member
Kae
What kind of captcha does your version use? Is it GD based or text?

Michele
 

kae

New Member
the example code uses GD (the captcha generator was not written by me). It might be interesting to make it more robust, though (I was only giving it as an example of a slightly more complete mailer) - you have something in mind?
 

mneylon

Administrator
Staff member
The problem with image based captcha is that you are basically waving two fingers at anyone who is visually impaired, so a text based challenge is a saner option IMHO
 

kae

New Member
that can be arranged. I'll write one tomorrow evening (got a baby in my arms right now)
 
Status
Not open for further replies.
Top