Hello. I am trying to get a specific email function to work but can not. My site has several contact forms depending on the department you are trying to contact. So far it sends from the same controller php file with no differences. I want the email form to send to different people depending on the page the person sent the email form. So far the controller file calls the group ID it needs, but I need it to send it to certain emails depending on that id.
This is what I have so far that doesn’t work:
<?php
class ContactsController extends AppController {
var $name = 'Contacts';
function thanks()
{
$this->layout = 'scgsah_default';
}
function ask($id)
{
$this->layout = 'scgsah_default';
$this->set('groupname', $this->requestAction('groups/getGroupName/'.$id));
$this->set('groups', $this->requestAction('groups/getGroupList'));
if (empty($this->data))
{
}
else
{
$this->cleanUpFields();
if ($this->Contact->save($this->data))
{
$this->Session->setFlash($this->data['Contact']['firstname'].' '.$this->data['Contact']['lastname'] . ', your message has been sent.');
$this->redirect('/contacts/thanks');
//SIMPLE PHP EMAIL - Added by Nicole 10.14.08
$to = "example@mail.com" if ($id !=19) {"anotheremail@example.com"};
$subject = "Ask A Student Form";
$message = 'Type of Question: '.$this->data['Contact']['groupname']."\
\
".'Email: '.$this->data['Contact']['email']."\
\
".'Name: '.$this->data['Contact']['firstname'].' '.$this->data['Contact']['lastname']."\
\
".'Address: '.$this->data['Contact']['address']."\
\
". 'City: '.$this->data['Contact']['city']."\
\
". 'State: '.$this->data['Contact']['state']."\
\
". 'Zip Code: '.$this->data['Contact']['zip']."\
\
". 'Phone: '.$this->data['Contact']['phone']."\
\
". 'Current School: '.$this->data['Contact']['organization']."\
\
". 'Subscribed to Newsletter: '.$this->data['Contact']['newsletter']."\
\
". 'Question: '.$this->data['Contact']['message'];
$from = $this->data['Contact']['email'];
$headers = "From: $from";mail($to,$subject,$message,$headers);echo "Mail Sent.";
}
else
{
$this->Session->setFlash($this->data['Contact']['firstname'].', '.$this->data['Contact']['firstname'] . ' has not been added.');
$this->redirect('/contacts/thanks');
}
}
}
function subscribe()
{
$this->layout = 'scgsah_default';
if (empty($this->data))
{
}
else
{
$this->cleanUpFields();
if ($this->Contact->save($this->data))
{
$this->Session->setFlash($this->data['Contact']['firstname'].', '.$this->data['Contact']['lastname'] . '! Your message has been sent.');
$this->redirect('/contacts/thanks');
}
else
{
$this->Session->setFlash($this->data['Contact']['firstname'].', '.$this->data['Contact']['firstname'] . ' has not been added.');
$this->redirect('/contacts/thanks');
}
}
}
}
?>
Any help would be appreciated.