views:

23

answers:

1

Hi guys, I'm so dang close. I'm trying to print the contents of a form to an email. Here's what I have. I'm able to pront the contents as an array to my view, but not send the values to the email.

public function indexAction()
    {
        $formData = array();
        $emailData = array();

    $form = new Application_Form_Contact();

        if ($this->_request->isPost()) {
            $formData = $this->_request->getPost();
            if ($form->isValid($formData)) {

                foreach ($formData as $d){
                    $emailData[] = $d;
                }

                 $mail = new Zend_Mail();

                 $mail->setFrom('[email protected]', 'user');
                 $mail->AddTo('[email protected]', 'joel');
                 $mail->setSubject('from form');
                 $mail->setBodyText($emailData);
                 $mail->send();

            } else {
                // bad stuff happens
            }
        }
        $this->view->form = $form;
    }
}
+1  A: 

emailData needs to be a string.

$emailData = "Email content: ";
foreach ($formData as $d){
   $emailData .= $d . "\r\n";
}

Not the most elegant thing but it will work.

Iznogood
Man-thanks so much for this help and your earlier help! All pieces are now in place and working!
Joel
hmm-what is strange is that the formData being emailed is not going through the validator even though when I view the form in the process view, it has stripped html, etc. Idea why?
Joel
You know you should really just use it normally. If in your form you have a <input type="text" name="something" /> Then just use $emailData['something'] directly without looping thru it all.
Iznogood
Well, I wanted to create this as a generic form to use on a lot of my sites, so I just wanted to loop it. I ended up just having to loop the getValues instead of formData and that worked out-I guess filtering only works on getValues
Joel