Hi All,

My situation is this:

I am running a CMS system where each category represents a market place, each market place has it's own email address defined in the database. I would like a form to be placed in each category that sends to the email address specified in the database.

Where I am at the moment:

I have successfully gotten PHP DynaForm to do this but PHP DynaForm does not send emails in a nice html template so I would like to use formmail from: http://www.tectite.com/

My code surrently looks like this and does not work:

<?php if($page[adminemail]) {
printf( "<form method=\"post\" action=\"http://www.marketsonline.com.au/contact_m_admin/formmail.php\" name=\"SampleForm\">
    <input type=\"hidden\" name=\"env_report\" value=\"REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT,AUTH_TYPE,REMOTE_USER\">
    <input type=\"hidden\" name=\"recipients\" value=\"%s\" />
    <input type=\"hidden\" name=\"required\" value=\"email:Your email address\" />
    <input type=\"hidden\" name=\"subject\" value=\"Sample FormMail Testing\" />

<table border=\"1\" cellspacing=\"5%\">
<tr>
    <td>
    <p>Please enter your name:</p>
    </td>
    <td><input type=\"text\" name=\"realname\" />
    </td>
</tr>
<tr>
    <td>
    <p>Please enter your email address:</p>
    </td>
    <td><input type=\"text\" name=\"email\" />
    </td>
</tr>
<tr>
    <td><p>May we contact you?</p>
    </td>
    <td>
        Yes <input type=\"radio\" name=\"contact\" value=\"Y\" checked />
        No <input type=\"radio\" name=\"contact\" value=\"N\" />
     </td>
</tr>
<tr>
    <td valign=\"top\">
    <p>Please enter your message:</p>
    </td>
    <td><textarea name=\"mesg\" rows=\"10\" cols=\"50\"></textarea>
    </td>
</tr>
<tr>
    <td><input type=\"submit\" value=\"Submit\" /></td>
    <td></td>
</tr>
</table>
</form>",$page['adminemail'],$page['title']);
} ?>

I have also attached my formmail script. As you might know the email addresse used on the form also have to be defined in formmail but formmail doesn't seem to like what I'm doing. The line in question is 2958.

If someone could tell me what I am doing wrong or suggest a better / easier method I would be so damn happy!

    I'm a bit confused here...are you just wanting to send emails based on that admin address? If so, you could run some authentication then use something like this

    <?php
    
    $to = $page["adminemail"];
    $subject = "Sample FormMail Testing";
    $msg = "Put your message in the message variables\n\n";
    $msg .= "Name: " . $_POST["realname"] . "\n";
    $msg .= "Email: " . $_POST["email"] . "\n";
    $msg .= "Contact them: " . $_POST["contact"] . "\n";
    $msg .= "Message: " . $_POST["mesg"];
    $headers = "From: " . $_POST["email"];
    
    mail($to, $subject, $msg, $headers);
    
    // Check to see if mail ran, output some sort of message to user.
    
    ?>

      Sorry to confuse you but the puzzle is only just starting to come together for me. Thanks for taking the time to answer my questions though. Really appreciate it and hope to return the favour to another newbe one day.

      So you think I should not use formmail? I am definitely open to suggestion. I was thinking of hiding admin emails from spammer etc that is why I was using formmail.

      In the example below, I take it that it is to be placed in it's own php file then referenced from the form? Is that right? Again i do appreciate any clear instuction I can get.

      You ROCK!

        no problem. I personally prefer PHP over formmails, since it's my own code and I don't have to use any hidden variables in the code.

        You can put this code in a separate PHP file or in the same on as the form. If you put it in the same one as the form, you'll just need to check if the user has submitted the form. Here's the basic logic-flow.

        SUBMIT
        - Yes -> Check Form Input
        - No -> Display Form

        CHECK FORM INPUT (Required Fields were filled out properly)
        - Yes -> Process Form
        - No -> Display form with error messages

        PROCESS FORM (check that mail is sent)
        - Yes -> Display a message to user saying their info has been submitted
        - No -> Display an error saying there was a problem sending their email

        If you're on the same script (which helps avoid too many PHP files), you could do something like this:

        First, assign a name='submit' to your submit button in HTML so that we can grab that variable by it's name in PHP. Then, to check if the form has been submitted:

        <?php
        
        if( isset($_POST["submit"]) )
        {
             // Display Form here - Could be object, or put the HTML here.
             $form->DisplayForm();
        } 
        else 
        {
             // Form has not been submitted
             // Error checking, send the email, then display message on success.
        
        }
        
        ?>
        
          Write a Reply...