Send different emails to the USER depending on form field selections

  • jayrigby
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 15
  • Thank you received: 0

jayrigby created the topic: Send different emails to the USER depending on form field selections

Hi there,

We have a case where when a user completes the form there is a particular question that asks them to choose between 3 different options for a select list.

Depending on the choice we wish to send the user a different email for each selection to give them more information.

Is there any way to send more emails on submit in addition to just mailback and admin emails?

Much appreciated!
#228891
  • Posts: 2986
  • Karma: 104
  • Thank you received: 394

mihaela replied the topic: Send different emails to the USER depending on form field selections

Hello,

There is a way to achieve what you want, but it requires a bit of coding.

The way to achieve this is do define email content In End Submit for every email that you want to send.

Here are the instructions on how to do so:

1) In Properties of your form uncheck the Mail notification checkbox. Also, in the Advanced options of element where user enters his email uncheck the Mailback checkbox if it was checked.

It is necessary to turn off these email notifications in order for this to work.

2) Go to Advanced options of your form > More options > Submit pieces > End Submit, set Type to Custom and in the code area below paste in the following code:
$this->execPieceByName('ff_InitLib');
$from = 'address@domain.com';
$fromname = 'From Name';
$subject = 'Your Email Subject'; // Change to your preferred Email subject

$recipient = ff_getSubmit('email');
$sel = ff_getSubmit('selectlistname'); // replace selectlistname with the Name of your select list element


$body = '';
foreach ($this->maildata as $data) {
  $body .= $data[_FF_DATA_TITLE].": ".$data[_FF_DATA_VALUE].nl() . "\r\n"; 
}

$this->sendMail($from, $fromname, 'adminemail@test.com', $subject, $body );  // replace adminemail@test.com with your admin email
//that line of code sends submitted data to the admin email
$this->sendMail($from, $fromname, $recipient, $subject, $body ); //this line of code sends submitted data to the email address that user has entered in email field of your form

//Define content of the three emails

//First email content
$body1 = 'This is the first email';

//First email content
$body2 = 'This is the second email';

//First email content
$body3 = 'This is the third email';


if($sel == "value1") {
$this->sendMail($from, $fromname, $recipient, $subject, $body1 );  }
if($sel == "value2") {
$this->sendMail($from, $fromname, $recipient, $subject, $body2 );  }
if($sel == "value3") {
$this->sendMail($from, $fromname, $recipient, $subject, $body3 );  }

//in the code above replace value1, value2 and value3 with values of the three options in your select list
NOTE: You have to adjust the code for your form following the instructions in comments.

Let me know whether you have managed to set this for your form.
If you have more questions, feel free to ask.

Regards,

Mihaela
#228904
The following user(s) said Thank You: geeksscript
  • Posts: 86
  • Thank you received: 1

geeksscript replied the topic: Send different emails to the USER depending on form field selections

Hi Mihaela!
I used above code but faced below few issues:
  1. It was not working with HTML email body & gave 500 error after submission. When removed HTML content, it worked.
  2. Even after specifying email from address in $from variable, email was sent via default Joomla address. The $fromname was also not considered
  3. After submission, I got a "You must provide at least one recipient email address." system notice

Please guide.
#232749
  • Posts: 2986
  • Karma: 104
  • Thank you received: 394

mihaela replied the topic: Send different emails to the USER depending on form field selections

Hello,

Here are the solutions to the issues that you are facing:

1. You are correct, this code is not working with HTML email body. In order to be able to display html email body $isHtml need to be set to true in sendmail() function.

Therefore you should define sendmail function like this:
$attachment=null;
$isHtml = true;
$this->sendMail($from, $fromname, $recipient, $subject, $body1, $attachment, $isHtml);
You can see an example here crosstec.org/en/forums/18-languages/1254....html?start=6#232045 .

2. The $fromname should be the name of the sender of the email. The address in $from address is the address that will be set as a reply-to address. It won't be set as senders email address because in that case there is a big chance that it ends being recognized as spam.
Here you can read more about it crosstec.org/en/support/online-documenta...r-email-address.html .
Also, since you wrote that $fromname isn't recognized, are you sure that the email you are receiving isn't the standard email, but the one that you have created in End Submit?

3. Please check whether you have Mail notification checkbox checked. If you have check whether you have "Mail recipient(s)" email address defined.
Also, check whether you have a field in your form where user enters email address named "email".

Let me know whether this helped and if you have more questions, feel free to ask.

Regards,

Mihaela
#232826
  • Posts: 86
  • Thank you received: 1

geeksscript replied the topic: Send different emails to the USER depending on form field selections

Hi,

I use below to fetch the form field value:
$contact_details = ff_getSubmit('ContactDetails');

ContactDetails is the name of Check group element type having 3 values.

In the email, only the 1st selected value is being printed and all other selected values are being ignored. How can I have all the selected values shown in the email?

Please guide.
#238821
Moderators: ForumSupporttomeperica
Time to create page: 0.064 seconds

New Icon Packs Category!

Crosstec is now offering icon packs.

If you are a paying subscriber, icon packs are automatically added to your account.

Check out our icon packs page!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Summer Sale!

50% discount on all of our extension subscription plans, templates and icon packs!

Get Your Subscription Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99 for just 49! (Summer Sale)

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here