Welcome Guest, Not a member yet? Register   Sign In
Email does not send (codeigniter 2.0.1 )
#1

[eluser]Masum[/eluser]
MY FORM PAGE: myform.php
Code:
<html>
<head>
<title>My Form</title>
<style type="text/css">
p { color:#F00;}
</style>
</head>
<body>
    <?php echo form_open('form'); ?>
    <table width="900px" align="center">
     <tr>
         <td align="right">Full Name</td>
   <td width="100px">&lt;input type="text" name="full_name" value="&lt;?php echo set_value('full_name'); ?&gt;" size="50" /&gt;&lt;/td>
            <td align="left"><p>&lt;?php echo form_error('full_name'); ?&gt;</p></td>
  </tr>
        <tr>
         <td align="right">Email Address</td>
            <td>&lt;input type="text" name="email" value="&lt;?php echo set_value('email'); ?&gt;" size="50" /&gt;&lt;/td>
            <td align="left"><p>&lt;?php echo form_error('email'); ?&gt;</p></td>
  </tr>
        <tr>
            <td align="right">Subject:</td>
            <td>&lt;input type="text" name="subject" value="&lt;?php echo set_value('subject'); ?&gt;" size="20" /&gt;&lt;/td>
            <td align="left"><p>&lt;?php echo form_error('subject'); ?&gt;</p></td>
       </tr>
       <tr>
            <td align="right">Comment</td>
            <td>&lt;textarea name="comment" rows="5" cols="40"&gt;&lt;?php echo set_value('comment'); ?&gt;&lt;/textarea&gt;&lt;/td>
            <td align="left"><p>&lt;?php echo form_error('comment'); ?&gt;</p></td>
        </tr>
        <tr>    
            <td></td>
            <td align="left">&lt;input type="submit" value="Submit" /&gt;&lt;/td>
            <td></td>
       </tr>
    </table>
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;



MY CONTROLLER: form.php
Code:
&lt;?php

class Form extends CI_Controller
{
function index()
{
  $this->load->helper(array('form', 'url'));
  $this->load->library('form_validation');
  $this->form_validation->set_rules('full_name', 'Full Name', 'required');
  $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
  $this->form_validation->set_rules('subject', 'Subject', 'required');
  $this->form_validation->set_rules('comment', 'Comment', 'required');
  if ($this->form_validation->run() == FALSE)
  {
   $this->load->view('myform');
  }
  else
  {
   $this->load->library('email');
   $this->config->item('protocol');

   $this->email->from($this->input->post('email'), $this->input->post('full_name'));
   $this->email->to('[email protected]');
   $this->email->subject('Email Test');
   $this->email->message($this->input->post('comment'));
   if($this->email->send())
   {
    echo 'Your email has been sent';
   }
   else
   {
    show_error($this->email->print_debugger());
   }
  }
}
}
?&gt;


CONFIG FILE: email.php
Code:
&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'localhost';
$config['smtp_port'] = 25;
$config['mailtype'] = 'html';


GETTING ERROR:

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: 1553



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

From: "Masum"
Return-Path:
Reply-To: "[email protected]"
X-Sender: [email protected]
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <[email protected]>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
=?utf-8?Q?Email_Test?=
tyh
#2

[eluser]keevitaja[/eluser]
you have to edit php.ini file and set a working smpt server address. atm it is localhost on port 25. unless you have smtp server on your local computer it is impossible to send out emails.
#3

[eluser]InsiteFX[/eluser]
Just set it to your online smtp server and it will work!
You know the one you receive all your emails from!
Code:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = smtp.comcast.net
; http://php.net/smtp-port
smtp_port = 25




Theme © iAndrew 2016 - Forum software by © MyBB