• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: PHP Email

PHP Email 3 years 6 months ago #40585

Been trying for days to figure out why this isn't working. Can anyone help?

I'm trying to send an email only if the text box is NOT empty.

Most recently tried this, but the admin email still goes out to all submissions, regardless of whether or not the comment field is blank.

In Script called before the Admin Email is sent section:
if ($_POST['form']['comment'] !== '') {
   $adminEmail['to'] = 'myemail@a.com';
} else {
   $adminEmail['to'] = NULL;
   $adminEmail['from'] = NULL;
}
The administrator has disabled public write access.

PHP Email 3 years 6 months ago #40586

  • sam.jako
  • sam.jako's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
Hi,

Exactly the same issue here. I'm using this code:
if (empty($_POST['form']['Remarks'])) { 
         $additionalEmail['to'] = "";
    }

(recipients email is filled out as standard, but should be wiped when 'remarks' field is left empty)
Unfortunately I have the same result as original poster -> all mails get sent whatsoever.
Last Edit: 3 years 6 months ago by sam.jako. Reason: Code snippet not showing properly
The administrator has disabled public write access.

PHP Email 3 years 6 months ago #40587

  • andreic
  • andreic's Avatar
  • NOW ONLINE
  • RSJoomla! Official Staff
  • Posts: 713
  • Thank you received: 59
Hello,

@makesomeonemeri you could try using the following:
if ($_POST['form']['comment'] !== '') {
   $adminEmail['to'] = 'myemail@a.com';
} else {
   $adminEmail['to'] = "";
   $adminEmail['from'] = "";
}

@sam.jako

If the field is named "remarks", then please try using:
if ($_POST['form']['remarks'] == '') {
   $additionalEmail['to'] = '';
   $additionalEmail['from'] = '';
}
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here
Regards,
RSJoomla! Development Team
The administrator has disabled public write access.

PHP Email 3 years 6 months ago #40589

@andreic - thanks. Unfortunately, this does not work. All admin emails continue to go out regardless of if the field is filled out or not.

Any other ideas?

Note - I do not have an email assigned on the Recipients Admin Emails.
The administrator has disabled public write access.

PHP Email 3 years 6 months ago #40590

  • sam.jako
  • sam.jako's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
@andreic Thank you for the reply

unfortunately no success. The form keeps on sending emails even when the 'Remarks' field is left blank by the user.

My full code for that section of RsForm is
if(!isset($_POST['form'])){
  if ($_POST['form']['Remarks']=='') { 
         $additionalEmail['to'] = '';
         $additionalEmail['from'] = '';
    }
 }

The first 'if' is for checking if the form has been newly submitted. If the form is just being revisited (after clicking a custom made confirmation link) the additional mails is not supposed to send. And it is'nt, so that part is working.
It is just the check for empty 'Remarks' field that is not working. Strange, because it should be easy...
Last Edit: 3 years 6 months ago by sam.jako. Reason: code not showing properly
The administrator has disabled public write access.

PHP Email 3 years 6 months ago #40595

  • adrianp
  • adrianp's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 631
  • Thank you received: 146
Hello,

This will work if the code is properly specified and your field name precisely matches the given field name (case sensitive). If the scripts provided on this reply do not help, it would be best if you check your actual $_POST data by placing the following temporarily in your scripting area and by submitting the form with or without comment/remarks (this way you can view what's being sent and how):
print_r($_POST);die;

@makesomeonemeri:
- have the Admin Email TO field already set to your email address via its configuration normally. This way the script can be simplified to only clear out the TO field, preventing the email from being sent if there was no comment.

- while editing the form > Form Properties > PHP Email Scripts > "Script called before the Admin Email is sent" area (ensure you're placing this in the correct scripting area):
//check the field naming to be precisely set. If this is "Comment" instead, adjust it accordingly:
if(empty($_POST['form']['comment'])){
	$adminEmail['to'] = '';
}

@sam.jako:
- same here, the field naming has to precisely match (case sensitive) and ensure you're placing the script in the correct scripting area; yours being the one designated for the Additional Email.

- the following particular IF you're using will never pass when a form is submitted since $_POST will always be available upon submit (implying the additional code enclosed in this IF statement will never trigger upon actual form submit):
if(!isset($_POST['form'])){
- the script you're looking for is this one instead (assuming the naming is correct):
if(empty($_POST['form']['Remarks'])){
	$additionalEmail['to'] = '';
}
This is not official customer support. To receive your support, submit a support ticket here.
The administrator has disabled public write access.
The following user(s) said Thank You: sam.jako, makesomeonemeri
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!