Welcome Guest, Not a member yet? Register   Sign In
Formmail
#2

[eluser]Derek Allard[/eluser]
You're on track in your last sentence. To do this I've always built the forum (you can use the form helper or build it yourself) and then use the email class to send stuff out.

On darkhorse.to I do it like this

Code:
function index()
    {
        $this->load->library('validation');
        $rules['name'] = "trim|required|max_length[50]";
        $rules['email'] = "trim|required|valid_email|max_length[50]";
        $rules['message'] = "trim|required|htmlentities|max_length[700]";
        
        $this->validation->set_rules($rules);
        
        $fields['name'] = 'Name';
        $fields['email'] = 'Email';
        $fields['message'] = 'Message';
    
        $this->validation->set_fields($fields);
        $this->validation->set_error_delimiters('<p class="error">', '</p>');

        if ($this->validation->run() == FALSE) {
            $data['pageTitle'] = 'Contact';
            $this->load->view('contact/index', $data);
        } else {
            $this->load->library('email');

            $name = $this->input->post('name');
            $email = $this->input->post('email');
            $message = $this->input->post('message');

            $this->email->from($email, $name);
            $this->email->to('[email protected]');
            $this->email->subject('Darkhorse contact form');
            $this->email->message($message . "\n\n-------------------\nIP address: " . $this->input->ip_address() . "\nServer name: " . gethostbyaddr($this->input->ip_address()));
            
            if ($this->email->send()) {
                $data['pageTitle'] = 'Contact';
                $this->load->view('contact/success', $data);
            } else {
                $data['pageTitle'] = 'Contact';
                $this->load->view('contact/failure', $data);
            }
        }    
    }

And here is the view
Code:
&lt;?php
    $this->load->view("header");
?&gt;
<h2 class="page_topic">Contact</h2>
<p>I’m Derek, and I build and program rock-solid web applications.  If you’d like to discuss work, please feel free to contact me.  Also, feel free to drop me a line if you just want to chat about web development. I’m good like that.</p>
<p><img src="&lt;?= base_url();?&gt;img/email.png" width="16" height="16" alt="email" /> <span id="myemail">derek (at) darkhorse (dot) to </span></p>
&lt;form id="contact_form" action="&lt;?= site_url('contact');?&gt;" method="post"&gt;
&lt;?=$this->validation->error_string; ?&gt;
    <p><label for="name">Name</label>
    &lt;input type="text" name="name" id="name" size="40" class="required" value="&lt;?php if ($this-&gt;validation->name) {echo $this->validation->name;}?&gt;" />
    </p>
    <p><label for="email">Email</label>
    &lt;input type="text" name="email" id="email" size="40" class="required" value="&lt;?php if ($this-&gt;validation->email) {echo $this->validation->email;}?&gt;" />
    </p>
    <p><label for="message">Message</label><br />
    &lt;textarea name="message" id="message" rows="5" cols="40"&gt;&lt;?php if ($this->validation->message) {echo $this->validation->message;}?&gt;&lt;/textarea&gt;
    </p>
    <p>&lt;input type="submit" value="send message" /&gt;</p>
&lt;/form&gt;
&lt;?php
    $this->load->view('footer');
?&gt;

I've actually been wanting to make some additions... I'll do a blog entry about it in the near future if you want.


Messages In This Thread
Formmail - by El Forum - 11-09-2007, 06:07 AM
Formmail - by El Forum - 11-09-2007, 06:25 AM
Formmail - by El Forum - 11-21-2007, 02:42 AM
Formmail - by El Forum - 11-21-2007, 06:49 AM
Formmail - by El Forum - 11-23-2007, 10:23 PM



Theme © iAndrew 2016 - Forum software by © MyBB