CodeIgniter Forums
message not appearing in email - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: message not appearing in email (/showthread.php?tid=21785)



message not appearing in email - El Forum - 08-20-2009

[eluser]jshultz[/eluser]
I'm using the email library to send emails from a simple "contact us" type form. Everything is working and emails are being sent but there's no message. The subject and all the other data works and even the form validation. It's just the message is dropped off and all that is sent is blank email.

Here's my email function:

Code:
class Email extends Controller
{
    function __construct()
    {
        parent::Controller();
    }
    
    function index()
    {
        $this->load->library('email');
          $data['page_title'] = 'Arrow Express';
          $data['banner'] = 'banner-contact';
          $data['page'] = 'contact'; // pass the actual view to use as a parameter
          $this->load->view('container',$data);
    }
    
    function send()
    {    
        $this->load->library('form_validation');
        
        // field name, error message, validation rules
        $this->form_validation->set_rules('name', 'Name', 'trim|required');
        $this->form_validation->set_rules('email', 'Email Address', 'trim|required|valid_email');
        $this->form_validation->set_rules('message', 'Comments', 'trim|required');
        
        if($this->form_validation->run() == FALSE)
        {
        $data['page_title'] = 'Arrow Express';
        $data['banner'] = 'banner-contact';
        $data['page'] = 'contact'; // pass the actual view to use as a parameter
        $this->load->view('container',$data);
        }
        else
        {
            // validation has passed. Now send the email
            $name = $this->input->post('name');
            $email = $this->input->post('email');
            $comments = $this->input->post('message');
            
            $this->load->library('email');
            $this->email->set_newline("\r\n");

            $this->email->from($email, $name);
            $this->email->to($email);        
            $this->email->subject('Arrow Express Contact Form');        
            $this->email->message($comments);

            $path = $this->config->item('server_root');
            $file = $path . '/ci_day4/attachments/newsletter1.txt';

            $this->email->attach($file);

            if($this->email->send())
            {
                //echo 'Your email was sent, fool.';
                redirect('/site/contact_confirmation/');
            }

            else
            {
                show_error($this->email->print_debugger());
            }            
        }
    }
}

And here's my contact form:

Code:
<?php echo form_open('email/send'); ?>
            <fieldset>
                <div id="" class="span-8">
                    <legend>
                        Use This Simple Form
                    </legend>
                    <br/>
                    &lt;?php
                    $name_data = array('name'=>'name', 'id'=>'name', 'value'=>set_value('name'));
                    $message_data = array('name'=>'message', 'id'=>'message', 'value'=>set_value('message'), 'rows'=>'5', 'class'=>'span-7');
                    
                    ?&gt;
                    <p>
                        <label for="name">
                            Name:
                        </label><br/>
                        &lt;?php echo form_input($name_data); ?&gt;
                    </p>
                    <p>
                        <label for="name">
                            Email Address:
                        </label><br/>
                        &lt;input type="text" name="email" id="email" value="&lt;?php echo set_value('email');?&gt;"&gt;
                    </p>
                </div>
                <div id="" class="span-7 last">
                    <label>
                        Comments
                    </label>
                    &lt;?php echo form_textarea($message_data); ?&gt;
                    <br/>
                    <p>
                        &lt;?php echo form_submit('submit', 'Submit'); ?&gt;
                    </p>
                    &lt;?php echo form_close(); ?&gt;
                </div>
            </fieldset>
            &lt;?php echo validation_errors('<p class="error">'); ?&gt;
            </div>



message not appearing in email - El Forum - 08-20-2009

[eluser]jshultz[/eluser]
I've also tried replacing
Code:
$this->email->message($comments);
with
Code:
$this->email->message('test message');
to see if it's a problem with passing the variable and it still doesn't work.


message not appearing in email - El Forum - 08-20-2009

[eluser]jshultz[/eluser]
Still working on this. I tried changing my email from being sent my gmail to being sent my sendmail. I'm still getting the same problem where there is no message body. name, subject, etc. all work. But there is no message body either plain text or html???? Any ideas?


message not appearing in email - El Forum - 08-20-2009

[eluser]jshultz[/eluser]
Discovered the problem thanks to help from the IRC channel. It was the file attachment that was causing the problem. Problem solved.


message not appearing in email - El Forum - 10-12-2009

[eluser]Brandon Jones[/eluser]
Hi, how did you work around this? Just use another email library?


message not appearing in email - El Forum - 10-12-2009

[eluser]jshultz[/eluser]
The problem I was having was it was trying to attach a file that didn't exist:

Code:
$file = $path . '/ci_day4/attachments/newsletter1.txt';



message not appearing in email - El Forum - 10-12-2009

[eluser]Brandon Jones[/eluser]
Thanks! I just figured this out myself (trying to generate a PDF in a directory that did not have write permissions).

Wish CI threw an error before handing off to mail(), but oh well.