Advertisement
Guest User

Untitled

a guest
Sep 9th, 2017
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. <?php
  2.  
  3. APPLICATION.INI
  4.  
  5. ; Config Mail
  6. resources.mail.transport.type = smtp
  7. resources.mail.transport.host = "smtp.gmail.com"
  8. resources.mail.transport.auth = login
  9. resources.mail.transport.username = youremail
  10. resources.mail.transport.password = emailPassword
  11. resources.mail.transport.ssl = "tls"
  12. resources.mail.transport.register = true
  13. resources.mail.defaultFrom.name = "Website"
  14.  
  15. FORM
  16.  
  17. class Application_Model_FormContact extends Zend_Form
  18. {
  19. public function __construct($options=null)
  20. {
  21. parent::__construct($options);
  22. $this->setName('contact');
  23. $this->setMethod('post');
  24. $this->setAction('/about/contact');
  25.  
  26. $title = new Zend_Form_Element_Text('title');
  27. $title->setAttrib('size', 35);
  28. $title->setRequired(true);
  29.  
  30. $sender = new Zend_Form_Element_Text('sender');
  31. $sender->addValidator('EmailAddress')
  32. ->addFilter('StringtoLower')
  33. ->setRequired(true)
  34. ->setAttrib('size', 35);
  35.  
  36. $message = new Zend_Form_Element_Textarea('message');
  37.  
  38. $submit = new Zend_Form_Element_Submit('submit');
  39. $submit->setLabel('Send');
  40.  
  41. $this->setDecorators(array(array('ViewScript',
  42. array('viewScript' => '_form_contact.phtml'))));
  43.  
  44. $this->addElements(array($title, $sender, $message, $submit));
  45. }
  46. }
  47.  
  48. CONTROLLER
  49.  
  50. public function contactAction()
  51. {
  52. $this->view->headTitle()
  53. ->append('Contact');
  54.  
  55. $form = new Application_Model_FormContact();
  56. $this->view->form = $form;
  57.  
  58. if($this->getRequest()->isPost() ) {
  59. if($form->isValid($this->_request->getPost())) {
  60. $subject = $form->getValue('title');
  61. $message = $form->getValue('message');
  62. $sender = $form->getValue('sender');
  63.  
  64. $mail = new Zend_Mail();
  65. $mail->setBodyText($message);
  66. $mail->setFrom($sender, 'Steve Sheen');
  67. $mail->setSubject($subject);
  68. $mail->addTo('email@gmail.com');
  69. $mail->send();
  70. }
  71.  
  72. }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement