to .= ','.JRequest::getVar('text_3');}?>Check0 is the name of the checkbox and text_3 is the name of the e-mail text field. I made tries but when the checkbox is marked no copy of e-mail is sent.I made tries on a personal wamp server and I obtain the errors:Notice: Undefined variable: emails in C:\wamp\www\monsite\components\com_chronocontact\libraries\customcode.php(64) : eval()'d code on line 3Notice: Undefined offset: 0 in C:\wamp\www\monsite\components\com_chronocontact\libraries\customcode.php(64) : eval()'d code on line 3Can anybody help me?I specify that it's work on another site with the version 3.1RC2 of chronocontact while on the site it is the version 3.1RC5.5.Thank you for the help.Jean-Pierre (France)"> Problems to send a copy of e-mail - Forums

Forums

Problems to send a copy of e-mail

MILORD65 08 Jun, 2010
Hello,

I made a form on which I put a checkbox that the sender has to mark to receive a copy of the message.
I added the code in "On Submit code - before sending email":

<?php
if(JRequest::getVar('check0')) {
$emails[0]->to .= ','.JRequest::getVar('text_3');
}
?>

Check0 is the name of the checkbox and text_3 is the name of the e-mail text field.
I made tries but when the checkbox is marked no copy of e-mail is sent.
I made tries on a personal wamp server and I obtain the errors:
Notice: Undefined variable: emails in C:\wamp\www\monsite\components\com_chronocontact\libraries\customcode.php(64) : eval()'d code on line 3
Notice: Undefined offset: 0 in C:\wamp\www\monsite\components\com_chronocontact\libraries\customcode.php(64) : eval()'d code on line 3

Can anybody help me?
I specify that it's work on another site with the version 3.1RC2 of chronocontact while on the site it is the version 3.1RC5.5.
Thank you for the help.

Jean-Pierre (France)
nml375 08 Jun, 2010
Hi Jean-Pierre,
The Email API in ChronoForms has changed alot since 3.1RC2. There's a short example regarding how to use this in RC5.5 in the #31 FAQ, though I'll post the needed code here.
<?php
$MyForm =& CFChronoForm::getInstance('form_name_here');
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);

if (JRequest::getVar('check0')) {
  $rcpt = $MyFormEmails->getEmailData(1, 'to') . ',' . JRequest::getVar('text_3');
  $MyFormEmails->setEmailData(1, 'to', $rcpt);
}
?>


/Fredrik
MILORD65 09 Jun, 2010
Hello Fredrik,

Thank you very much for your help.
Its works very well !! 🤣
Thanks you for your answer.

Best regards

Jean-Pierre
Angelcrazy 03 Aug, 2010
Hi guys, I know I am a year late, but I see you have done this but I am getting some trouble getting it to work for me. The form code is:

<h1 class="title">Contact</h1>
<div class="instructions">
Please fill in the form below and submit your enquiry.  All information marked with an asterisk * is mandatory. 
</div>
<div class="leftform">
<div class="formrow">
    <label class="join">Subject of enquiry:</label><input type="text" class="text" name="subject">
</div>
<div class="formrow">
    <label class="join">Title</label><input type="text"  class="text" name="title">
</div>
<div class="formrow">
    <label class="join">Forename</label><input type="text"  class="text" name="forename">
</div>
<div class="formrow">
    <label class="join">Surname</label><input type="text"  class="text" name="surname">
</div>

<div class="formrow">
    <label class="join">E-mail address</label><input type="text"  class="text" name="email">
</div>

<div class="formrow">
    <label class="join">Telephone Number</label><input type="text"  class="text" name="phone">
</div>
</div>
<div class="rightform">
<span class="detailsLabel">Please enter details of your enquiry in the field below</span>
<div class="textrow">
 <textarea name="question" rows="4" cols="70"></textarea>
</div>
<div class="checkBox"><input name="check0" type="checkbox" value="" /> Email a copy of this message to your own address.
<INPUT TYPE="image" SRC="images/submit.png"  class="button" BORDER="0" ALT="Submit Form">
</div>
</div>


and in my On Submit code - before sending email:
<?php
$MyForm =& CFChronoForm::getInstance('contactus');
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);

if (JRequest::getVar('check0')) {
  $rcpt = $MyFormEmails->getEmailData(1, 'to') . ',' . JRequest::getVar('email');
  $MyFormEmails->setEmailData(1, 'to', $rcpt);
}
?>


What do you think I am doing wrong here? The form sends an email properly, but doesn't send a copy email when the checkbox is clicked.

David
nml375 03 Aug, 2010
Hi David,
The problem is that the getVar method of JRequest always retrn a value (default is '', unless otherwize specified). Since you assigned the value '' to the checkbox aswell, there's no way to tell whether the checkbox was checked or not.

Add a value, such as value='yes' and then modify the code slightly:
...
$check = JRequest::getVar('check0');
if ($check == 'yes') {
...

/Fredrik
Angelcrazy 03 Aug, 2010
Hiya nml375,

Thanks for that alot, I changed my code now and it is running that code now fine. Except it still isn't sending an email to the sender?

This code is working now as I tested an echo in it:
$check = JRequest::getVar('check0');
if ($check == 'yes') {


However, what would I need to do to set it up to send a second email then? Hmm. Do I need to create another email template. Sorry i'm only a bit familiar with ChronoForms.

David

EDIT: actually it might be working, just testing.
neronero 01 Sep, 2010
Hello,

First, I have to say, I'm very new in this, and my knowledge is very basic.

I created a form, and tried to follow the above mentioned solution, but I lost somewhere. Here is my code:
$check = JRequest::getVar('check0');
if ($check == 'yes')
 {<?php
$MyForm =& CFChronoForm::getInstance('erdeklodes');
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);

if (JRequest::getVar('check0')) {
  $rcpt = $MyFormEmails->getEmailData(1, 'to') . ',' . JRequest::getVar('text_15');
  $MyFormEmails->setEmailData(1, 'to', $rcpt);
}
>


But of course it is not good. Can you help me what I'm doing wrong?
GreyHead 01 Sep, 2010
Hi neronero,

What are you actually trying to do here?

Does your form send an email without this code?

Bob
neronero 01 Sep, 2010
Hi,

I'm really sorry I was not clear.

I created a form, and I received the mail. After it I added a checkbox and the sender has to mark to receive a copy of the message.

As I understood from the previous notes, I have to add a code in "On Submit code - before sending email"

So I tried this, without succes.
GreyHead 01 Sep, 2010
Hi neronero,

Please try this. Set up the email and in the Properties Box set 'Enabled' to 'No'

In the OnSubmit Before box add this code
<?php
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
$check = JRequest::getVar('check0');
if ($check == 'yes') {
  $MyFormEmails->setEmailData(1, 'enabled', true);
}
?>


Bob
neronero 02 Sep, 2010
Dear Bob,

Thank you for the help.

The problem is that after the suggested modifications, not only the copy of the emial, but even the original message haven't arrived.

Any other idea, what can I do wrong?

Thanks
Rita
GreyHead 02 Sep, 2010
Hi Rita,

Please turn on Form Debug, submit the form and copy and paste the resulting Debug messages and email report here.

Bob
neronero 09 Sep, 2010
Hi Bob!

Here is the debug message:

1. Form passed first SPAM check OK
2. Form passed the submissions limit (if enabled) OK
3. Form passed the Image verification (if enabled) OK
4. Form passed the server side validation (if enabled) OK
5. $_POST Array: Array ( [text_0] => Company name [text_1] => test [text_15] => [text_2] => Name[text_3] => 123 [text_5] => [text_13] => [text_4] => [check0] => Array ( [0] => igen ) [text_14] => [Küldés] => Küldés [d743c2a10ea6b469864951d993db471a] => 1 [1cf1] => b8ef43674a4d5ce82d4c282c57beb5d5 [chronoformname] => erdeklodes )
6. $_FILES Array: Array ( )
7. Form passed the plugins step (if enabled) OK
8. An email has been SENT successfully from (Company name)email to email
9. Debug End


thanks in advance
GreyHead 10 Sep, 2010
Hi Rita,

And the dummy email report from the same page please.

From the report here it looks as though the To & From Email addresses for your email are both the same. This seems to get emails dropped quite often. Please test with different To & From Email addresses.

Bob
neronero 13 Sep, 2010
Hi Bob!

Here is the email:

From: Name [email]
To:email
CC:
BCC:
Subject: Érdeklődés

Cégnév
Company name
Székhely
test
Email
[email]name@gmail.com[/email]
KapcsolattartĂł
XY
Telefonszám
123
Jelenlegi szolgáltató

Jelenlegi szerződés lejárta

Éves fogyasztás

Ăśzenet

Másolatot kérek az üzenetből
igen

Sorry, the fields name are Hungarian...

I modified the To & From Email addresses not to be the same, but nothing changed

Thank for your help.
GreyHead 13 Sep, 2010
Hi Rita,

That all looks good.

Can your site send emails OK from other pages?

Bob

PS By all means email or PM me the site URL and a SuperAdmin login and I'll take a quick look.
This topic is locked and no more replies can be posted.