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
switch($field->ClassName){
case "EditableEmailField" :
if($field->SendCopy){
$recipientAddresses[] = $data[$field->Name];
$sendCopy = true;
$values[$field->Title] = '<a style="white-space: nowrap" href="mailto:'.$data[$field->Name].'">'.$data[$field->Name].'</a>';
}
break;
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->populateTemplate($emailData);
$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)
if($attachments){
foreach($attachments as $file){
$email->attachFile($filename,$filename);
}
}
$email->send();
}
Around line 400:
if($sendCopy) {
// send to each of email fields
$emailToSubmiter = new UserDefinedForm_SubmittedFormEmailToSubmitter($submittedFields);
$emailToSubmiter->populateTemplate($emailData);
$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
$emailToSubmiter->send();
}
}
Hope that helps someone. Can anyone confirm a bug at all and is the issue still the same for 0.2?
Cheers
Aaron