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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

All other Modules /

Discuss all other Modules here.

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

Userforms 0.1 - "From" Field in email empty

Go to End

4 Posts   1570 Views


Community Member, 607 Posts

23 June 2009 at 1:42pm

Hi all.

We have Userforms 0.1 installed on 2.3.1 and have a problem where the email comes through, but the "From" field of the email is blank. Both the confirmation to the user and to the person set as "Email submission to:" in the CMS have this problem. And now it seems that some email systems are blocking these emails for lack of a "From" header.

It's strange, I could have sworn that I have another site with the same setup where the "From" address for the user, is the site owners, and the "From" address for the person set as "Email submission to:" is the user who filled out the form (allowing a quick reply).

Using Email::setAdminEmail in _config.php fixes the issue somewhat, but we want our customers to be able to hit reply when they get a contact message from their site.

Any ideas?


Forum Moderator, 5523 Posts

23 June 2009 at 4:28pm

Has your form got a EmailField form field which SS could detect a from address? Has to be a EmailField (not a TextField)

Web Designer Perth

Community Member, 49 Posts

23 June 2009 at 5:56pm

Same issue here.

@willr - yes, form has EmailField.


Community Member, 607 Posts

24 June 2009 at 9:56am

I am wondering if this is a bug or oversight now. Yes I have an email field, and in the code for userforms/code/UserDefinedForms.php, this is checked and all email addresses on the form are added to an array called $recipientAddresses.

Function Process - line 332

					case "EditableEmailField" : 
							$recipientAddresses[] = $data[$field->Name];
							$sendCopy = true;
							$values[$field->Title] = '<a style="white-space: nowrap" href="mailto:'.$data[$field->Name].'">'.$data[$field->Name].'</a>';

The thing is, nothing is done with this array. The emails that are setup and sent further down the method do not have calls to the setFrom() method at all. Just populateTemplate(), setSubject(), setContent() and setTo().

So I edited my local UserDefinedFrom.php class to do this and it works as desired. My changes are between the MODADC comments:

Line 381

if( $this->EmailOnSubmit ) {
			$email = new UserDefinedForm_SubmittedFormEmail($submittedFields);			
			$email->setTo( $this->EmailTo );
			$email->setSubject( $this->Title );
			// MODADC - This block sets the from field of the email (for site owner) to be that of the user (if one was entered)
			// If the form doesn't ask for an email address, the from field will be set to that of the "Email Submissions to:" address in the CMS
      if(!empty($recipientAddresses)) {
        $email->setFrom( $recipientAddresses[0] );
      } else {
        $email->setFrom( $this->EmailTo );
      // END MODADC

			// add attachments to email (<1MB)
				foreach($attachments as $file){

Around line 400:

if($sendCopy) {
			// send to each of email fields
			$emailToSubmiter = new UserDefinedForm_SubmittedFormEmailToSubmitter($submittedFields);
			$emailToSubmiter->setSubject( $this->Title );
			foreach( $recipientAddresses as $addr ) {
				$emailToSubmiter->setBody( $this->EmailMessageToSubmitter );
				$emailToSubmiter->setTo( $addr );
				// MODADC - Set from header
				$emailToSubmiter->setFrom( $this->EmailTo ); 
				// MODADC - Set from header

Hope that helps someone. Can anyone confirm a bug at all and is the issue still the same for 0.2?