Could not instantiate mail function

ozneil 02 Oct, 2008
Hi,

I am using v3.0 stable ChronoForms and am finding this to be an invaluable (and great value for money!) tool.

Can someone help me with a "Could not instantiate mail function" problem as I am fairly new at this and am a bit lost?

I have a form that accepts a name and 4 email addresses and then uses the input from the form to send an email to each of the 4 addresses. It works well if 4 email addresses are entered but there is an error message, "Could not instantiate mail function" if any of the email addresses are left blank.

The form is at: http://greenedgeethical.com.au/index.php?option=com_chronocontact&Itemid=74

Email setup is as follows:

To: [email]info@greenedgeethical.com.au[/email]
Subject: Investment Opportunity
Dynamic BCC: email_1,email_2,email_3,email_4
Fromname: Greenedge Ethical Investments Ltd
FromEmail: [email]info@greenedgeethical.com.au[/email]


Form Code is as follows:
<div  class="form_item"><div class="form_element cf_heading"><h1 id="" class="cf_text">Spread the Word!</h1></div></div>

<div  class="form_item"><div class="form_element cf_text"><span class="cf_text">If you know anyone who may be interested in investing in the IPO then please enter your name and the email addresses of up to four friends or acquaintances and we will send them one email in regard to the IPO. Email addresses will not be used for any other purpose. Thank-you for your help.</span></div>

<div class="clear"> </div></div><div  class="form_item"><div class="form_element cf_textbox"><label class="cf_label">Your Name:</label><input class="cf_inputbox" maxlength="60" size="30" id="name" name="name" type="text"></div>

<div class="clear"> </div></div><div  class="form_item"><div class="form_element cf_textbox"><label class="cf_label">Email Address 1:</label><input class="cf_inputbox validate-email" maxlength="60" size="30" id="email_1" name="email_1" type="text"></div>

<div class="clear"> </div></div><div  class="form_item"><div class="form_element cf_textbox"><label class="cf_label">Email Address 2:</label><input class="cf_inputbox validate-email" maxlength="60" size="30" id="email_2" name="email_2" type="text"></div>

<div class="clear"> </div></div><div  class="form_item"><div class="form_element cf_textbox"><label class="cf_label">Email Address 3:</label><input class="cf_inputbox validate-email" maxlength="60" size="30" id="email_3" name="email_3" type="text"></div>

<div class="clear"> </div></div><div  class="form_item"><div class="form_element cf_textbox"><label class="cf_label">Email Address 4:</label><input class="cf_inputbox validate-email" maxlength="60" size="30" id="email_4" name="email_4" type="text"></div>

<div class="clear"> </div></div><div  class="form_item"><div class="form_element cf_button"><input value="Submit" name="undefined" type="submit"><input value="Reset" type="reset"></div><div class="clear"> </div></div>

I am thinking I could set the emails to a non-blank default value such as [email]ignore@greenedgeethical.com.au[/email] before the form is presented but don't know the code to use or where exactly to enter it.

Suggestions are very welcome!

Thanks,

Neil
Chidlow, Western Australia.
GreyHead 02 Oct, 2008
Hi ozneil,

This is almost certainly because you are trying to send to an empty - and therefore invalid - email address.

The problem is that CF is pretty automatic in the way that it handles these field values so you need to do the cleaning yourself.

First off I suggest that you make them into an array by using name="friend_email[]" for all four fields and then putting {friend_email} in the BCC field.

You still need to get rid of any empty values in this array. Unfortunately the first time you can do this is in the OnSubmit Before box but by then the result array has been turned into a list. Here's a bit of code that should handle this:
<?php
$temp_array = explode($_POST['friend_email']);
foreach ($temp_array as $key => $value) {
    if ($temp_array[$value] == "") {
        unset($temp_array[$key]);
    }
}
$_POST['friend_email'] = implode($temp_array);
unset($tems_array);
?>
Note: not tested and may need de-bugging.

Bob
Max_admin 02 Oct, 2008
Hi ozneil,

try to overwrite your file under components/com_chronocontact/ with the one attached and it will fix it!
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
ozneil 02 Oct, 2008
Wow you guys rock! 2 solutions within a couple of hours. In that 2 hours I learned a bit of PHP and actually came up with a work around (not nearly so elegant as your solutions). I added the following to the "On Submit code - before sending email:" section:


<?php
if (empty($_POST['email_1'])) $_POST['email_1'] = "null@greenedgeethical.com.au";
if (empty($_POST['email_2'])) $_POST['email_2'] = "null@greenedgeethical.com.au";
if (empty($_POST['email_3'])) $_POST['email_3'] = "null@greenedgeethical.com.au";
if (empty($_POST['email_4'])) $_POST['email_4'] = "null@greenedgeethical.com.au";
?>

So there are no blank email addresses any more. I will try your alternative solutions and let you know how I go.

Thanks so much!

Neil
Max_admin 02 Oct, 2008
Thanks Neil, please try my file without you code so we make sure it solves your issue so it gets included in the new release!

Cheers

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
ozneil 02 Oct, 2008
Hi Max, Hi Bob,

I have tried out your suggested solutions. Bob - it took me a while to debug your suggested code as I am new to PHP but you are spot on! Here is what I ended up with in the OnSubmit Before box to make it work:


<?php
$temp_array[] = $_POST['email_1'];
$temp_array[] = $_POST['email_2'];
$temp_array[] = $_POST['email_3'];
$temp_array[] = $_POST['email_4'];
foreach ($temp_array as $key=> $value) {
    if ($temp_array[$key] == "") unset($temp_array[$key]);
}
$_POST['friend_email'] = implode(",", $temp_array);
unset($temp_array);
?>


Max - I did remember to remove the code in the OnSubmit Before box and then uploaded the components/com_chronocontact/chronocontact.php you provided. This worked like a charm straight away!

Thanks both for your prompt and helpful advice. I am definitely a ChronoForms fan now and I have posted a rave review on the http://www.joomla.org web site.

All the best,

Neil.
Max_admin 02 Oct, 2008
Great! Thanks Neil for letting me know this!

Best regards

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.