TOPIC:

Send different emails to the USER depending on form field selections 2 years 1 month ago #228891

  • Topic Author
  • jayrigby
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 15
  • Thanks: 0
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!

Please Log in or Create an account to join the conversation.

Send different emails to the USER depending on form field selections 2 years 1 month ago #228904

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 415
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
The following user(s) said Thank You: geeksscript

Please Log in or Create an account to join the conversation.

Send different emails to the USER depending on form field selections 1 year 8 months ago #232749

  • geeksscript
  • Offline
  • Senior Breezer
  • Senior Breezer
  • Posts: 86
  • Thanks: 1
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.

Please Log in or Create an account to join the conversation.

Send different emails to the USER depending on form field selections 1 year 7 months ago #232826

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 415
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

Please Log in or Create an account to join the conversation.

Send different emails to the USER depending on form field selections 7 months 4 weeks ago #238821

  • geeksscript
  • Offline
  • Senior Breezer
  • Senior Breezer
  • Posts: 86
  • Thanks: 1
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.

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Moderators: ForumSupport
Time to create page: 0.051 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

Summer Sale!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

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!