[eluser]Adam Griffiths[/eluser]
[quote author="audiopleb" date="1217296087"]Ah good. I just wanted to narrow down the possible reasons. I'll have a thorough look at this tomorrow.[/quote]
Ok thank you.
[eluser]johnwbaxter[/eluser]
This is me being lazy, but could you post one view one controller and one model that i can just copy and paste and try in my install?
Sorry
[eluser]Adam Griffiths[/eluser]
The controller...email.php
Code: <?php
class Email extends Controller
{
function __construct()
{
parent::Controller();
$this->load->helper('security');
$this->load->helper('email');
}
function index()
{
echo("You cannot access this page directly");
}
function quick()
{
if($_POST['quickform'])
{
$name = xss_clean($_POST['name']);
$email = xss_clean($_POST['email']);
$subject = xss_clean($_POST['subject']);
$message = xss_clean($_POST['message']);
if($name | $email | $subject | $message == NULL)
{
$data['title'] = 'Quick Enquiry';
$this->load->view('header', $data);
$this->load->view('form/quick_posterror');
$this->load->view('footer');
}
elseif(valid_email($email))
{
$this->load->model('email_model');
$this->email_model->quick($name, $email, $subject, $message);
$data['title'] = 'Quick Enquiry';
$this->load->view('header', $data);
$this->load->view('form/success');
$this->load->view('footer');
}
else
{
$data['title'] = 'Quick Enquiry';
$this->load->view('header', $data);
$this->load->view('form/invalid_email');
$this->load->view('footer');
}
}
else
{
$data['title'] = 'Quick Enquiry';
$this->load->view('header', $data);
$this->load->view('form/quick_posterror');
$this->load->view('footer');
}
}
}
/* End of file email.php */
/* Location: system/application/controllers/ */
Model...email_model.php
Code: <?php
class Email_model extends Model
{
function __construct()
{
parent::Model();
}
function index()
{
echo("You cannot access this page directly");
}
function quick($name, $email, $subject, $message)
{
echo("Name: ".$name."<br />");
echo("Email: ".$email."<br />");
echo("Subject: ".$subject."<br />");
echo("Message: ".$message."<br />");
$config['protocol'] = 'sendmail';
$this->email->initialize($config);
$this->email->from($email, $name);
$this->email->reply_to($email, $name);
$this->email->to('[email protected]');
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();
echo $this->email->print_debugger();
}
}
/* End of file email.php */
/* Location: system/application/models/ */
View...form/success.php
Code: <div id="content">
<div class="box">
<div id="justcontent">
<p class="head">Success!</p>
<p>Thank you for sending us an email! Your message has now been sent. We will reply as soon as we can.</p>
</div>
</div>
</div>
I use two other views, if you want to just create an emptyfile instead of getting a CI error, they are forms/invalid_email.php and form/quick_posterror.php
Thank you.
[eluser]johnwbaxter[/eluser]
Are you autoloading the e-mail "library"? cos i can't see it being loaded in your code.
[eluser]Adam Griffiths[/eluser]
Yes it's in my autoload.php file...
For reference...
Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| AUTO-LOADER
| -------------------------------------------------------------------
| This file specifies which systems should be loaded by default.
|
| In order to keep the framework as light-weight as possible only the
| absolute minimal resources are loaded by default. For example,
| the database is not connected to automatically since no assumption
| is made regarding whether you intend to use it. This file lets
| you globally define which systems you would like loaded with every
| request.
|
| -------------------------------------------------------------------
| Instructions
| -------------------------------------------------------------------
|
| These are the things you can load automatically:
|
| 1. Libraries
| 2. Helper files
| 3. Plugins
| 4. Custom config files
| 5. Language files
| 6. Models
|
*/
/*
| -------------------------------------------------------------------
| Auto-load Libraries
| -------------------------------------------------------------------
| These are the classes located in the system/libraries folder
| or in your system/application/libraries folder.
|
| Prototype:
|
| $autoload['libraries'] = array('database', 'session', 'xmlrpc');
*/
$autoload['libraries'] = array('database', 'email');
/*
| -------------------------------------------------------------------
| Auto-load Helper Files
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['helper'] = array('url', 'file');
*/
$autoload['helper'] = array('url', 'form');
/*
| -------------------------------------------------------------------
| Auto-load Plugins
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['plugin'] = array('captcha', 'js_calendar');
*/
$autoload['plugin'] = array();
/*
| -------------------------------------------------------------------
| Auto-load Config files
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['config'] = array('config1', 'config2');
|
| NOTE: This item is intended for use ONLY if you have created custom
| config files. Otherwise, leave it blank.
|
*/
$autoload['config'] = array();
/*
| -------------------------------------------------------------------
| Auto-load Language files
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['language'] = array('lang1', 'lang2');
|
| NOTE: Do not include the "_lang" part of your file. For example
| "codeigniter_lang.php" would be referenced as array('codeigniter');
|
*/
$autoload['language'] = array();
/*
| -------------------------------------------------------------------
| Auto-load Models
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['model'] = array('model1', 'model2');
|
*/
$autoload['model'] = array();
/*
| -------------------------------------------------------------------
| Auto-load Core Libraries
| -------------------------------------------------------------------
|
| DEPRECATED: Use $autoload['libraries'] above instead.
|
*/
// $autoload['core'] = array();
/* End of file autoload.php */
/* Location: ./system/application/config/autoload.php */
[eluser]johnwbaxter[/eluser]
have you got logging turned on?
I had it in the model and it worked, then I just moved the sending function into a controller and it worked fine also.
You have spelt your e-mail address properly haven't you?!
[eluser]Adam Griffiths[/eluser]
I'm not sure I might have, how would I go about looking at the logs?
Yea everything was spelt correctly with both emails.
[eluser]johnwbaxter[/eluser]
Oh i did strip out some code.
Try this little lot:
View: (form/form.php):
Code: <html>
<body>
</div>
<div id="sidebar">
<div class="box">
<p class="head">Quick Enquiry Form</p>
<p><?php echo form_open('test/quick');?></p>
<p class="head2">Name:
<input type="text" name="name" class="quickform" /></p>
<p class="head2">Email2:
<input type="text" name="email2" class="quickform" /></p>
<p class="head2">Subject:
<input type="text" name="subject" class="quickform" /></p>
<p class="head2">Message:
<textarea class="quickformbig" rows="0" cols="0" name="message"></textarea></p>
<p><input type="submit" name="quickform" class="send" /></p>
</form>
</div>
</div>
<div id="footer">
<div id="copyright">
<div id="text1">© Nanoswift MMVIII</div>
</div>
</div>
</body>
</html>
controller: (test.php)
Code: <?php
class Test extends Controller{
function Test()
{
parent::Controller();
}
function quick()
{
$name = $_POST['name'];
$email2 = $_POST['email2'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$this->load->model('emailmod');
$this->emailmod->quick($name, $email2, $subject, $message);
$data['title'] = 'Quick Enquiry';
$this->load->view('header', $data);
$this->load->view('form/success');
$this->load->view('footer');
}
}
?>
model: (emailmod.php)
Code: <?php
class Emailmod extends Model
{
function __construct()
{
parent::Model();
$this->load->library('email');
}
function index()
{
echo("You cannot access this page directly");
}
function quick($name, $email2, $subject, $message)
{
echo("Name: ".$name."<br />");
echo("Email: ".$email2."<br />");
echo("Subject: ".$subject."<br />");
echo("Message: ".$message."<br />");
$this->email->from($email2, $name);
$this->email->reply_to($email2, $name);
$this->email->to('[email protected]');
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();
echo $this->email->print_debugger();
}
}
?>
I stripped out a load of your code to minimise on problems and changed a few names of stuff just because i was changing things around.
Here is the controller that loads the form view if you want it:
Code: <?php
class Testy extends Controller{
function Testy(){
parent::Controller();
}
function index(){
$this->load->view('form/form');
}
}
?>
let me know how you get on.
[eluser]johnwbaxter[/eluser]
Your logs should be in /system/logs, make sure the logs folder is writeable. Logging is set in config.php
[eluser]Adam Griffiths[/eluser]
Everything works great now! Thanks!
|