Welcome Guest, Not a member yet? Register   Sign In
Having problems sending emails
#1

[eluser]Keloo[/eluser]
I'm trying to send emails with the CI email lib, and I'm getting some errors like:
Quote:A PHP Error was encountered

Severity: Warning

Message: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()

Filename: libraries/Email.php

Line Number: 1540

An Error Was Encountered
Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.

From: "Some name"
Return-Path:
Reply-To: "someone@yahoo.com"
X-Sender: someone@yahoo.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <4dbe8ae281f65@yahoo.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
=?utf-8?Q?Testing_mail?=
This is just a test

here is the function responsible for sending emails:
Code:
function contact()
  {
        $this->load->library('form_validation');
      
      $this->form_validation->set_rules('contact-email', 'Email', 'trim|required|valid_email');
      $this->form_validation->set_rules('contact-name', 'Name', 'trim|required|min_length[5]');
      $this->form_validation->set_rules('subject', 'Subject', 'trim|required|min_length[5]');
      $this->form_validation->set_rules('message', 'Message', 'trim|required|max_length[500]');
        
        if($this->form_validation->run() == FALSE)
        {
           $data['body'] = "Contact";
           $data['title'] = 'Site/Contact';
           $data['main_content'] = 'contact';
           $this->load->view('includes/template',$data);
        }
        else
        {
            
            
            $config = Array(
                        'protocol' => 'sendmail',
                        'smtp_host' => 'ssl://smtp.googlemail.com',
                        'smtp_port' => 465,
                        'smtp_user' => '[email protected]',
                        'smtp_pass' => 'testing'  
             );
             $this->load->library('email');

            $this->email->from($this->input->post('contact-email'), $this->input->post('contact-name'));
            $this->email->to('[email protected]');        
            $this->email->subject($this->input->post('subject'));        
            $this->email->message($this->input->post('message'));
            
            $this->load->library('email',$config);
            $this->email->set_newline("\r\n");
            
            
            if($this->email->send())
            {
                $data['body'] = "Contact";
                $data['title'] = 'Site/Contact';
                  $data['main_content'] = 'contact_success';
                 $this->load->view('includes/template',$data);
            }
            
            else
            {
                show_error($this->email->print_debugger());
            }
        }    
  }

and the view:
Code:
<aside class="grid_13 omega push_2 prefix_1">
    &lt;?php $logged_in = $this->session->userdata('logged_in'); ?&gt;
    
    &lt;?php if(!isset($logged_in) || $logged_in != TRUE): ?&gt;  
        &lt;?php $this->load->view('includes/login_form'); ?&gt;    
    &lt;?php else: ?&gt;
        &lt;?php $this->load->view('includes/users_area'); ?&gt;  
    &lt;?php endif?&gt;
  </aside>
&lt;/header&gt;
  <div id="page-wrap" class="container_24">
  <section id="main" class="grid_16 push_4">
      <h2>Contact</h2>
      &lt;?php echo form_open('site/contact'); ?&gt;
      <fieldset>        
          <label>From: </label>
          &lt;input type="email" name="contact-email" value="&lt;?php echo set_value('contact-email'); ?&gt;" /&gt;
          &lt;?php echo form_error('contact-email','<p class="error">','</p>'); ?&gt;
        
          <label>Name: </label>
          &lt;input type="text" name="contact-name" value="&lt;?php echo set_value('contact-name'); ?&gt;" /&gt;
          &lt;?php echo form_error('contact-name','<p class="error">','</p>'); ?&gt;
                  
          <label for="subject">Subject: </label>
          &lt;input type="text" name="subject" id="subject" value="&lt;?php echo set_value('subject'); ?&gt;"/&gt;
          &lt;?php echo form_error('subject','<p class="error">','</p>'); ?&gt;
          
          <label for="message">Message: </label>
          <p>&lt;textarea name="message" rows="10" cols="50" value="&lt;?php echo set_value('message'); ?&gt;"&gt;&lt;/textarea></p>
          &lt;?php echo form_error('message','<p class="error">','</p>'); ?&gt;
          
         <button type="submit">Send </button>  
      </fieldset>                
    &lt;/form&gt;
    </section>
  </div>

I really can't figure out what I'm doing wrong... How should I make it work ?
#2

[eluser]InsiteFX[/eluser]
Did you setup your smtp in php.ini like the error says?

InsiteFX
#3

[eluser]Keloo[/eluser]
Quote:[mail function]
;For Win32 only.
http://php.net/smtp
SMTP = localhost
http://php.net/smtp-port
smtp_port = 25

I've enabled http://php.net/smtp, SMTP = localhost and http://php.net/smtp-port.
I'm getting the same error. I really don't know what should I do to make it work properly.
#4

[eluser]InsiteFX[/eluser]
Use you smtp server! like I have comcast and I use their smtp server for sending email from my localhost.

This will be the same that you have your regular email setup for on your system.

InsiteFX
#5

[eluser]Keloo[/eluser]
Thanks, I've changed the smtp server and it works now Big Grin
#6

[eluser]vicman[/eluser]
I recommend using phpmailer




Theme © iAndrew 2016 - Forum software by © MyBB