Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Email a Copy of Form Submission

Go to End



Community Member, 545 Posts

26 September 2009 at 8:05am

I'm trying to set up a Form that gets emailed to an admin once its submitted but it doesn't seem to be working. Here is the Form and Submit function from my RegistrationPage_Controller

function UserRegistrationForm() {
      // Create fields
	  $companyTypeList = array(
			'Retail' => 'Retail',
			'Online' => 'Online',
			'Distributor' => 'Distributor',
			'Press' => 'Press'
	  $recaptchaField = new RecaptchaField('');
	  $recaptchaField->jsOptions = array('theme' => 'white');
      $fields = new FieldSet(
							 new FieldGroup (
											 new HeaderField('Personal Information', 3),
											 new LiteralField("explanation","<p>To Set-up Your Account</p>"),
											 new TextField('FirstName', 'First Name'),
											 new TextField('Surname','Last Name'),
											 new EmailField('Email','Email'),
											 new ConfirmedPasswordField('Password'),
							 new FieldGroup (
											 new HeaderField('Company Information', 3),
											 new LiteralField("explanation","<p>To Verfiy Eligibility</p>"),
											 new TextField('CompanyName','Company Name'),
											 new TextField('CompanyURL','Company Website'),
											 new TextField('HomePhone','Company Phone'),
											 new TextField('Address','Address'),
											 new TextField('AddressLine2','Address Line 2'),
											 new TextField('City','City'),
											 new TextField('State','State or Province'),
											 new TextField('Country','Country'),
											 new TextField('TaxIDNumber','TaxIDNumber'),
											 new TextField('Distributor','Distributor'),
											 new TextField('SalesRep','Sales Rep'),
											 new DropdownField('CompanyType','Company Type',$companyTypeList),
											 new TextareaField('Notes','Description'),
											 new HiddenField('PageID', '', $this->ID)
      // Create actions
      $actions = new FieldSet(
         new FormAction('doApplication', 'Submit')
      return new Form($this, 'UserRegistrationForm', $fields, $actions);
   function doApplication($data, $form) {
      $application = new UserApplication();
	  $application->RegistrationPageID = $this->ID;
	  //return print_r($application);

	  //E-mail Review Contents:
	  //Set data
	  $From = $data['Email'];
	  $To = "hardcoded@email.address";
	  $Subject = "New User Registration" . + $data['Email'];
	  $email = new Email($From, $To, $Subject);
	  //send mail