Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- APPLICATION.INI
- ; Config Mail
- resources.mail.transport.type = smtp
- resources.mail.transport.host = "smtp.gmail.com"
- resources.mail.transport.auth = login
- resources.mail.transport.username = youremail
- resources.mail.transport.password = emailPassword
- resources.mail.transport.ssl = "tls"
- resources.mail.transport.register = true
- resources.mail.defaultFrom.name = "Website"
- FORM
- class Application_Model_FormContact extends Zend_Form
- {
- public function __construct($options=null)
- {
- parent::__construct($options);
- $this->setName('contact');
- $this->setMethod('post');
- $this->setAction('/about/contact');
- $title = new Zend_Form_Element_Text('title');
- $title->setAttrib('size', 35);
- $title->setRequired(true);
- $sender = new Zend_Form_Element_Text('sender');
- $sender->addValidator('EmailAddress')
- ->addFilter('StringtoLower')
- ->setRequired(true)
- ->setAttrib('size', 35);
- $message = new Zend_Form_Element_Textarea('message');
- $submit = new Zend_Form_Element_Submit('submit');
- $submit->setLabel('Send');
- $this->setDecorators(array(array('ViewScript',
- array('viewScript' => '_form_contact.phtml'))));
- $this->addElements(array($title, $sender, $message, $submit));
- }
- }
- CONTROLLER
- public function contactAction()
- {
- $this->view->headTitle()
- ->append('Contact');
- $form = new Application_Model_FormContact();
- $this->view->form = $form;
- if($this->getRequest()->isPost() ) {
- if($form->isValid($this->_request->getPost())) {
- $subject = $form->getValue('title');
- $message = $form->getValue('message');
- $sender = $form->getValue('sender');
- $mail = new Zend_Mail();
- $mail->setBodyText($message);
- $mail->setFrom($sender, 'Steve Sheen');
- $mail->setSubject($subject);
- $mail->addTo('email@gmail.com');
- $mail->send();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement