I'm trying to send a form submission email to myself (myemail@email.com) and confirmation to a customer (emailID). It works fine when sending to myemail@email.com, but when I try to add a second value, like this for example: ("sendto" => "myemail@email.com", "emailID",) the script isn't sending anything at all. I've tried a number of combinations, but I can't seem to figure it out. I've pasted scripts below. Any help is much appreciated! Thank you in advance.
Here's the code:
<?php
$fields = array(
/* List the name of each field element below. Put each between double quotes(" ") and end every line with a comma(,). The name should be the exact same spelling and capitalization as the name attribute in the <input> or <textarea> tag it is referenceing. Whatever order these are in is the order they will appear in the email that is sent. */
"name",
"email",
"company",
"phone",
"state",
"comments",
);
$labels = array (
/* Everything before the "=>" should be the same as above. After the "=>" is what will appear in the email before the matching content from the form. (e.g. if you put: "email" => "Email Address:", then the email will have: "Email Address: someguy@domain.com" for the email address. */
"name" => "First Name:",
"email" => "Email Address:",
"company" => "Company:",
"phone" => "Phone:",
"state" => "State:",
"comments" => "Questions/Comments:",
);
$config = array(
/* Used to change configuration settings such as where to send the form submissions, the subject and where to send the user after they submit the form */
"nameID" => "name", // Insert the id of the field containing the users name, this will be used as the "from" name.
"emailID" => "email", // Insert the id of the field containing the users email address, this will use the users email address as the "from" email address.
"sendto" => "myemail@email.com", //"david@csmediagroup.com", // Insert the email addresses you want the form to send the submissions to, you may seperate several email addresses using commas(,)
"subject" => "Contact Us Submission", // Insert the subject you want the email to have here
"message" => "*** Contact Us Submission ***", // Insert anything you want in the body of the email (before the contents of the form) here! You can start a new line by using "\n" (without quotes). Use a backslash(\) before any double quotes(" ") or dollar signs($) to prevent errors.
"redirect" => "thankyou.html", // The web address of the thank you page or other page the user is redirected to after submitting the form, note that it is relative to the page the form is on
);
The form controller script:
<?php
class CMG_CCFP_FormController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$verify = Mage::getSingleton('core/session')->getFormSubmitted();
if ($verify == 'Yes') {
Mage::getSingleton('core/session')->setFormSubmitted();
$params = $this->getRequest()->getParams();
if (isset($params['configName'])) {
include(Mage::getRoot().'/code/community/CMG/CCFP/form-configurations/'.$params['configName'].'.php');
$message = $config['message'];
foreach($fields as $value) {
if (isset($params[$value])) {
$message .= "\n$labels[$value] $params[$value]";
}
}
$mail = new Zend_Mail();
$mail->setBodyText($message);
$mail->setFrom($params[$config['emailID']], $params[$config['nameID']]);
$mail->addTo($config['sendto']);
$mail->setSubject($config['subject']);
try {
$mail->send();
}
catch(Exception $ex) {
Mage::getSingleton('core/session')->addError('There was an error submitting your request.');
}
//Redirect back to index action of this controller
$this->_redirect($config['redirect']);
}
else {
die('There was an error with the form!');
}
}
else {
die('An error occured! Please go back and try submitting the form again.');
}
}
}
...And the actual form itself:
<?php echo '<div style="display:none;" id="baseurl">'.Mage::getBaseUrl().'</div>'; ?>
<div class="ccfp-main">
<form id="contact_us" class="ccfp" onsubmit="return checkAll(this)" action="<?php echo $this->getUrl('ccfp/form') ?>index" method="post">
<input type="hidden" name="configName" value="ContactUs" />
<h4 class="legend">Contact Us</h4>
<p>
<label for="name">Name</label>
<input name="name" id="name" title="Name" value="" class="required-entry" type="text" />
</p>
<p>
<label for="email">Email</label>
<input name="email" id="email" title="Email" value="" class="required-entry" type="text" />
</p>
<p>
<label for="company">Company</label>
<input name="company" id="company" title="Company" value="" class="" type="text" />
</p>
<p>
<label for="phone">Phone</label>
<input name="phone" id="phone" title="Phone" value="" class="" type="text" />
</p>
<p>
<label for="state">State</label>
<input name="state" id="state" title="State" value="" class="" type="text" />
</p>
<p>
<label for="comments">Comments/Questions</label>
<textarea name="comments" id="comments" title="Comments/Questions" value="" class="" rows="3" cols="50"></textarea>
</p>
<p>
<!-- DO NOT EDIT! CAPTCHA IMAGE SCRIPT! -->
<img src="<?php echo Mage::getBaseUrl(); ?>ccfp/captcha" id="captchaImage" />
<!-- END CAPTCHA IMAGE -->
</p>
<p>
<label for="security_code">Security Code</label>
<!-- START CAPTCHA INPUT BOX -->
<input class="required-entry" id="security_code" name="security_code" value="" title="Security Code" type="text" />
<!-- END CAPTCHA INPUT BOX -->
</p>
<p><button class="button" type="submit"><span><span>Submit!</span></span></button></p>
</form>
</div>