Welcome Guest, Not a member yet? Register   Sign In
Mail sending problems.
#11

[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. Smile
#12

[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 Wink
#13

[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.
#14

[eluser]johnwbaxter[/eluser]
Are you autoloading the e-mail "library"? cos i can't see it being loaded in your code.
#15

[eluser]Adam Griffiths[/eluser]
Yes it's in my autoload.php file...

For reference...
Code:
&lt;?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 */
#16

[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?!
#17

[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.
#18

[eluser]johnwbaxter[/eluser]
Oh i did strip out some code.

Try this little lot:

View: (form/form.php):

Code:
&lt;html&gt;
&lt;body&gt;
</div>

<div id="sidebar">
    
    <div class="box">
    <p class="head">Quick Enquiry Form</p>
    <p>&lt;?php echo form_open('test/quick');?&gt;</p>
    <p class="head2">Name:
    &lt;input type="text" name="name" class="quickform" /&gt;&lt;/p>
    <p class="head2">Email2:
    &lt;input type="text" name="email2" class="quickform" /&gt;&lt;/p>
    <p class="head2">Subject:
    &lt;input type="text" name="subject" class="quickform" /&gt;&lt;/p>
    <p class="head2">Message:
    &lt;textarea class="quickformbig" rows="0" cols="0" name="message"&gt;&lt;/textarea></p>
    <p>&lt;input type="submit" name="quickform" class="send" /&gt;&lt;/p>
    &lt;/form&gt;
    </div>
    
    </div>
    
    <div id="footer">
    <div id="copyright">
    <div id="text1">&copy; Nanoswift MMVIII</div>
    </div>
    </div>
    
&lt;/body&gt;
&lt;/html&gt;

controller: (test.php)

Code:
&lt;?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');
    }
    
}

?&gt;

model: (emailmod.php)
Code:
&lt;?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();
    }
}

?&gt;

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:
&lt;?php

class Testy extends Controller{




function Testy(){

parent::Controller();


}

function index(){

$this->load->view('form/form');
}


}

?&gt;

let me know how you get on.
#19

[eluser]johnwbaxter[/eluser]
Your logs should be in /system/logs, make sure the logs folder is writeable. Logging is set in config.php
#20

[eluser]Adam Griffiths[/eluser]
Everything works great now! Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB