php - Testing SilverStripe email contact forms from local server -


i building contact form sends email upon submission using combination of approaches provided in silverstripe documentation (introduction frontend forms, , simple contact form).

the code (included below) seems working fine, wondering if possible send test emails local server (in case, mamp) test functionality.

many in advance

public function contactform() {         $form = form::create(             $this,             __function__,             fieldlist::create(                 textfield::create('name','')                     ->setattribute('placeholder','name*')                     ->addextraclass('form-field'),                 emailfield::create('email','')                     ->setattribute('placeholder','email*')                     ->addextraclass('form-field'),                 textareafield::create('message','')                     ->setattribute('placeholder','message*')                     ->addextraclass('form-field')             ),             fieldlist::create(                 formaction::create('submit', 'send message')                     ->setusebuttontag(true)                     ->addextraclass('text-button')             ),             requiredfields::create('name','email','message')                     );          $form->addextraclass('contact-form');          return $form;     }       public function submit($data, $form){         $email = new email();          $email->setto('email@email.com');         $email->setfrom($data['email']);         $email->setsubject("contact message {$data["name"]}");          $messagebody = "             <p><strong>name:</strong> {$data['name']}</p>             <p><strong>message:</strong> {$data['message']}</p>         ";         $email->setbody($messagebody);         $email->send();          $form->sessionmessage("thanks message, i'll can",'good');          return $this->redirectback();     } 

edit: 8/04/17

as per have updated sendmail fields in php.ini files in mamp (both in mamp/bin/php/php5.6.10/conf , mamp/conf/php5.6.10) to:

; unix only.  may supply arguments (default: "sendmail -t -i"). ;sendmail_path =/usr/sbin/sendmail -t -i -f  ryanachten@gmail.com 

as per have updated mysite/_config/config.yml include:

email:   send_all_emails_to: 'ryanachten@gmail.com' 

all no avail...

yes - emails sent using silverstripe email class can redirected testing purposes:

# file: conf/configurefromenv.php if(defined('ss_send_all_emails_to')) {     config::inst()->update("email","send_all_emails_to", ss_send_all_emails_to); } 

reference

then used override email destinations here:

# file email/email.php public function send($messageid = null) {     // ...     if($sendallto = $this->config()->send_all_emails_to) {         $subject .= " [addressed $to";         $to = $sendallto;         // ... 

reference

so utilise this, define ss_send_all_emails_to in environment configuration:

# file: _ss_environment.php define('ss_send_all_emails_to', 'your@email.com'); 

Comments