Form sender email address not showing as sender, admin is

Permalink
I have combed through countless threads regarding this issue. My client wants it so that when someone submits a form, that the person submitting the form's email address is displayed in the sender area. The option to make the sender's email so that you can reply to it works, but the admin email address shows instead of the senders address. It is counter intuitive that you can set the sender's email to be replied to but the admin email displays. Is it me or does that make no sense?

Is there a simple fix for this? I am running 5.6.3, and the form controller is in a new location within the core directory. I have tried to override the form controller with a patch from an old post with no luck.

This long and windy thread does not get to the root of the problem which is swapping the admin email with the sender's email address in the "from" area.

http://www.concrete5.org/community/forums/customizing_c5/email-form...

shondy
 
Remo replied on at Permalink Reply
Remo
The problem is that in time of SPF protections, you simply shouldn't fake the actual sender address. By setting reply-to only, you can make sure you won't have any issues with SPAM filter while you can still hit the reply button in your mail client.

While it would look better, I would never recommend to override the sender in this way, it will cause more support problems at some point and get your customer upset as soon as some mails get filtered.
juliandale replied on at Permalink Reply 1 Attachment
juliandale
I'm sure what Remo is saying makes sense, but if your client is happy to ignore that advice, this is how I do it:

1. Copy the file from /concrete/blocks/form/controller.php and paste it to /blocks/form/controller.php

The file will look pretty empty, but the important bit is here:
class FormBlockController extends Concrete5_Controller_Block_Form {}


Within that class, you need to paste the function called action_submit_form from within the form controller class that is located at /concrete/core/controllers/form.php

So, you'll have it looking something like this:
class FormBlockController extends Concrete5_Controller_Block_Form {
  function action_submit_form() {
    // ... tons of code snipped out ...
  }
}


From there, you can make the changes to the function to use an email address field as the FROM address as well as the REPLY-TO address. To do that, add the line
$senderEmail=$answer;

to the bit that handles the 'Email Address' type of form fields, like so:
}elseif($row['inputType']=='email'){
  $answerLong="";
  $answer=$txt->sanitize($_POST['Question'.$row['msqID']]);
  $senderEmail=$answer; // << ADD THIS LINE
  if(!empty($row['options'])) {
    $settings = unserialize($row['options']);
    if(is_array($settings) && array_key_exists('send_notification_from', $settings) && $settings['send_notification_from'] == 1) {
      $email = $txt->email($answer);
      if(!empty($email)) {
        $replyToEmailAddress = $email;
      }
    }
  }
}elseif($row['inputType']=='telephone'){


Then, modify the bit that does the email sending to change it from this:
if( strlen(FORM_BLOCK_SENDER_EMAIL)>1 && strstr(FORM_BLOCK_SENDER_EMAIL,'@') ){
  $formFormEmailAddress = FORM_BLOCK_SENDER_EMAIL;  
}else{ 
  $adminUserInfo=UserInfo::getByID(USER_SUPER_ID);
  $formFormEmailAddress = $adminUserInfo->getUserEmail(); 
}
$mh = Loader::helper('mail');
$mh->to( $this->recipientEmail ); 
$mh->from( $formFormEmailAddress ); 
$mh->replyto( $replyToEmailAddress ); 
$mh->addParameter('formName', $this->surveyName);
$mh->addParameter('questionSetId', $this->questionSetId);
$mh->addParameter('questionAnswerPairs', $questionAnswerPairs); 
$mh->load('block_form_submission');
$mh->setSubject(t('%s Form Submission', $this->surveyName));


to this:
if (!empty($senderEmail)) {
  $replyToEmailAddress = $senderEmail;
} else if (strlen(FORM_BLOCK_SENDER_EMAIL)>1 && strstr(FORM_BLOCK_SENDER_EMAIL,'@')) {
  $replyToEmailAddress = FORM_BLOCK_SENDER_EMAIL;
} else {
  // get the site url and add no-reply@ to the front
  $replyToEmailAddress = "no-reply@" . $_SERVER['HTTP_HOST'];
}
$mh = Loader::helper('mail');
$mh->to( $this->recipientEmail ); 
$mh->from( $replyToEmailAddress ); // << NOTICE THIS HAS CHANGED TOO
$mh->replyto( $replyToEmailAddress ); 
$mh->addParameter('formName', $this->surveyName);
$mh->addParameter('questionSetId', $this->questionSetId);
$mh->addParameter('questionAnswerPairs', $questionAnswerPairs);


I've attached the controller.php file to go into the /blocks/form/ folder if it is easier for you.
juliandale replied on at Permalink Reply
juliandale
One last thing! This will only work if you have an Email Address type of field within your form. If you use a simple Text field and label it as Email or Email Address, then that won't get picked up by our modified form controller.
Remo replied on at Permalink Reply
Remo
I'd really recommend to talk your customer out of it. Mails which aren't received because of SPF problems are going to haunt you at some point.
shondy replied on at Permalink Reply
shondy
I fully understand the issue with spam and the issues it can bring up. The form from their old site was a PHP form that did put the sender's email address in the "from" field, so this is what they are expecting now.

The only issue if I do decide to patch the controller, is that it now isn't in the same location as in previous versions of C5. I tried to match the code in the new form controller in root\concrete\core\controllers\blocks\form.php, copied and added it to the root for the override following the same folder structure, but it didn't work.

Any suggestions?
shondy replied on at Permalink Reply
shondy
Sorry @juliandale- I misread what you wrote. I will follow your instructions and see how things turn out and report back.
shondy replied on at Permalink Reply
shondy
Moved the controller file to root/blocks/form/ but it's not working. I am not sure if I am missing a step. It seemed pretty straightforward, and I have an email field in the form set to reply to.
BHWW replied on at Permalink Reply
BHWW
I must agree with Remo that this isn't best practice, however... an alternative to showing the 'admin' email would be to add:

define('FORM_BLOCK_SENDER_EMAIL', 'no-reply@yourdomain.com');

To your config file, this then avoids confusion and they can still hit reply as long as you've set the form block up with and email field and the reply setting.
humbertomatos replied on at Permalink Reply
humbertomatos
Hi OnsiteDesigner,

Can you send the full path of the file to edit, i didnt find any file containing the string you posted.

Please send me the name and the full path of the file where I should insert the code you posted.

Thanks.
BHWW replied on at Permalink Reply
BHWW
Hi Humber

Assuming you are using 5.6, the config file is here:

/config/site.php

There is no config file in 5.7, but the forms better anyway.

Cheers
humbertomatos replied on at Permalink Reply
humbertomatos
Im using 5.7. I know the forms are better, but they dont give me an option to define the email sender address, so it keep using my e-mail.

I wish someone could help me with this.
servright replied on at Permalink Reply
Did you find a solution to this?

I've checked reply to this email address but it is still showing admin address.. I've deleted and re-added the email field but still the same results.