Jump to:

10993 Posts in 2727 Topics by 1818 members

All other Modules

SilverStripe Forums » All other Modules » Userforms 0.1 - "From" Field in email empty

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 1254 Views
  • Double-A-Ron
    Community Member
    604 Posts

    Userforms 0.1 - "From" Field in email empty Link to this post

    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?

  • Willr
    Forum Moderator
    5508 Posts

    Re: Userforms 0.1 - "From" Field in email empty Link to this post

    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

    Re: Userforms 0.1 - "From" Field in email empty Link to this post

    Same issue here.

    @willr - yes, form has EmailField.

  • Double-A-Ron
    Community Member
    604 Posts

    Re: Userforms 0.1 - "From" Field in email empty Link to this post

    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 );

             // 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?


Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.