Codeigniter Contact form submit returning timeout - php

Hi I am wondering if anyone could give me some insight into why my Codeigniter contact form just times out on submit?
I understand this is a beginner error but I feel like it is something I am completely overlooking. I have provided the controller and view.
I do have email.php setup in the Config file as well, with the various helpers and libraries loaded. Thank you in advance!
Controller
<?php
class contactform extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper(array('form','url'));
$this->load->library(array('session', 'form_validation', 'email'));
}
function index()
{
//set validation rules
$this->form_validation->set_rules('name', 'Name', 'trim|required|xss_clean|callback_alpha_space_only');
$this->form_validation->set_rules('email', 'Emaid ID', 'trim|required|valid_email');
$this->form_validation->set_rules('subject', 'Subject', 'trim|required|xss_clean');
$this->form_validation->set_rules('message', 'Message', 'trim|required|xss_clean');
//run validation on form input
if ($this->form_validation->run() == FALSE) {
//validation fails
$this->load->view('contact_form_view');
} else {
//get the form data
$name = $this->input->post('name');
$from_email = $this->input->post('email');
$subject = $this->input->post('subject');
$message = $this->input->post('message');
//set to_email id to receive emails
$to_email = 'littleliongirldesigns#gmail.com';
//configure email settings
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_user'] = 'email';
$config['smtp_pass'] = 'password';
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes
$this->load->library('email', $config);
$this->email->initialize($config);
//send mail
$this->email->from($from_email, $name);
$this->email->to($to_email);
$this->email->subject($subject);
$this->email->message($message);
if ($this->email->send()) {
// mail sent
$this->session->set_flashdata('msg','<div class="alert alert-success text-center">Your mail has been sent successfully!</div>');
redirect('contactform/index');
} else {
//error
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">There is error in sending mail! Please try again later</div>');
redirect('contactform/index');
}
}
}
//custom validation function to accept only alphabets and space input
function alpha_space_only($str)
{
if (!preg_match("/^[a-zA-Z ]+$/",$str)) {
$this->form_validation->set_message('alpha_space_only', 'The %s field must contain only alphabets and space');
return FALSE;
} else {
return TRUE;
}
}
}
?>
View
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3 well">
<?php $attributes = array("class" => "form-horizontal", "name" => "contactform");
echo form_open("contactform/index", $attributes);?>
<fieldset>
<legend>Contact Form</legend>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Name</label>
</div>
<div class="col-md-12">
<input class="form-control" name"name" placeholder="Your Name" type="text" value="<?php echo set_value('name'); ?>"/>
<span class="text-danger"><?php echo form_error('name'); ?></span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="email" class="control-label">Email ID</label>
</div>
<div class="col-md-12">
<input class="form-control" name="email" placeholder="Your email" type="text" value="<?php echo set_value('email'); ?>" />
<span class="text-danger"><?php echo form_error('email');?></span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="subject" class="control-label">Subject</label>
</div>
<div class="col-md-12">
<input class="form-control" name="subject" placeholder="Subject" type="text" value="<?php echo set_value('subject'); ?>"/>
<span class="text-danger"><?php echo form_error('subject');?></span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="message" class="control-label">Message</label>
</div>
<div class="col-md-12">
<textarea class="form-control" name="message" rows="4" placeholder="Your Message"><?php echo set_value('message');?></textarea>
<span class="text-danger"><?php echo form_error('message'); ?></span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input name="submit" type="submit" class="btn btn-primary" value="Send" />
</div>
</div>
</fieldset>
<?php echo form_close(); ?>
<?php echo $this->session->flashdata('msg'); ?>
</div>
</div>
</div>

Related

My Email is not working am getting error in my contact us page

My view
<div class="col-sm-6">
<div class="single_contant_left padding-top-90 padding-bottom-90">
<?php $attributes = array("class" => "form-horizontal", "name" => "contactform");
echo form_open("contactform/contactus", $attributes);?>
<div id="formid">
<div class="col-lg-8 col-md-8 col-sm-10 col-lg-offset-2 col-md-offset-2 col-sm-offset-1">
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<input type="text" class="form-control" name="name" value="<?php echo set_value('name'); ?>" placeholder="First Name" required>
<span class="text-danger"><?php echo form_error('name'); ?></span>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<input type="email" class="form-control" name="email" placeholder="Email" value="<?php echo set_value('email'); ?>" required>
<span class="text-danger"><?php echo form_error('email'); ?></span>
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<input type="text" class="form-control" name="subject" placeholder="Subject" value="<?php echo set_value('subject'); ?>" required>
<span class="text-danger"><?php echo form_error('subject'); ?></span>
</div>
</div>
</div>
<div class="form-group">
<textarea class="form-control" name="message" rows="7" placeholder="Message"><?php echo set_value('message'); ?></textarea>
<span class="text-danger"><?php echo form_error('message'); ?></span>
</div>
<div class="">
<input type="submit" name="submit" value="SEND MESSAGE" class="btn btn-lg">
</div>
</div>
<?php echo form_close(); ?>
<?php echo $this->session->flashdata('msg'); ?>
</div>
</div>
</div>
My controller
<?php
class Contactform extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper(array('form','url'));
$this->load->library(array('session', 'form_validation', 'email'));
}
function contactus()
{
//set validation rules
$this->form_validation->set_rules('name', 'Name', 'required');
$this->form_validation->set_rules('email', 'Emaid ID', 'trim|required|valid_email');
$this->form_validation->set_rules('subject', 'Subject', 'trim|required');
$this->form_validation->set_rules('message', 'Message', 'trim|required');
//run validation on form input
if ($this->form_validation->run() == FALSE)
{
//validation fails
$this->load->view('header_vw');
$this->load->view('center_vw');
$this->load->view('footer_vw');
}
else
{
//get the form data
$name = $this->input->post('name');
$from_email = $this->input->post('email');
$subject = $this->input->post('subject');
$message = $this->input->post('message');
//set to_email id to which you want to receive mails
$to_email = 'alshoja#gmail.com';
//configure email settings
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_user'] = '....#gmail.com';
$config['smtp_pass'] = 'als....#......';
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes
$this->load->library('email', $config);
$this->email->initialize($config);
//send mail
$this->email->from($from_email, $name);
$this->email->to($to_email);
$this->email->subject($subject);
$this->email->message($message);
if ($this->email->send())
{
// mail sent
$this->session->set_flashdata('msg','<div class="alert alert-success text-center">Your mail has been sent successfully!</div>');
redirect('contactform/contactus');
}
else
{
//error
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">There is error in sending mail! Please try again later</div>');
redirect('contactform/contactus');
}
}
}
//custom validation function to accept only alphabets and space input
function alpha_space_only($str)
{
if (!preg_match("/^[a-zA-Z ]+$/",$str))
{
$this->form_validation->set_message('alpha_space_only', 'The %s field must contain only alphabets and space');
return FALSE;
}
else
{
return TRUE;
}
}
}
Am getting error while sending message my server is configured good but mail is not sending from my site, how can I configure shall I want to give my password and username for sending mail in configuring section or else how can configure that please help :(
Am confused with them to address and from address in email configuration :(
Though I have done this several times, sending email through another provider is always a painful task.
Though this maybe ok,
$config['newline'] = "\r\n"; //use double quotes
but, Sending email with gmail smtp with codeigniter email library suggests
$this->email->set_newline("\r\n");
Also are you sure you allowed less secure apps in gmail?

Codeigniter email sending is not working [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I'm trying to send an email with an codeigniter contact us form but its not sending the email.
Yes I know this question has been asked before but I just want to know if I don't have any wrong code.
This is my controller file (Contactform.php) :
<?php error_reporting(-1);
ini_set('display_errors', 'On');
set_error_handler("var_dump");
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
class Contactform extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper(array('form','url'));
$this->load->library(array('session', 'form_validation', 'email'));
}
function index()
{
//set validation rules
//$this->form_validation->set_rules('name', 'Name', 'trim|required|xss_clean|callback_alpha_space_only');
$this->form_validation->set_rules('email', 'Email ID', 'trim|required|valid_email');
//$this->form_validation->set_rules('subject', 'Subject', 'trim|required|xss_clean');
//$this->form_validation->set_rules('message', 'Message', 'trim|required|xss_clean');
//run validation on form input
if ($this->form_validation->run() == FALSE)
{
//validation fails
$this->load->view('contact_form_view');
}
else
{
//get the form data
$name = $this->input->post('name');
$from_email = $this->input->post('email');
$subject = $this->input->post('subject');
$message = $this->input->post('message');
//zet to_email naar welk email je het contact form naar wilt laten sturen
$to_email = 'ferran1004#gmail.com';
//configure email settings
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_user'] = 'ferra#gmail.com';
$config['smtp_pass'] = 'tom10';
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes
$this->load->library('email', $config);
$this->email->initialize($config);
//send mail
$this->email->from($from_email, $name);
$this->email->to($to_email);
$this->email->subject($subject);
$this->email->message($message);
if ($this->email->send())
{
// mail sent
$this->session->set_flashdata('msg','<div class="alert alert-success text-center">Your mail has been sent successfully!</div>');
redirect('contactform/index');
}
else
{
//error
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">There is error in sending mail! Please try again later</div>');
redirect('contactform/index');
}
}
}
//custom validation function to accept only alphabets and space input
function alpha_space_only($str)
{
if (!preg_match("/^[a-zA-Z ]+$/",$str))
{
$this->form_validation->set_message('alpha_space_only', 'The %s field must contain only alphabets and space');
return FALSE;
}
else
{
return TRUE;
}
}
}
?>
And this is my view form file (contact_form_view.php):
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3 well">
<?php $attributes = array("class" => "form-horizontal", "name" => "Contactform");
echo form_open("Contactform/index", $attributes);?>
<fieldset>
<legend>Contact Form</legend>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Name</label>
</div>
<div class="col-md-12">
<input class="form-control" name="name" placeholder="Your Full Name" type="text" value="<?php echo set_value('name'); ?>" />
<span class="text-danger"><?php echo form_error('name'); ?></span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="email" class="control-label">Email ID</label>
</div>
<div class="col-md-12">
<input class="form-control" name="email" placeholder="Your Email ID" type="text" value="<?php echo set_value('email'); ?>" />
<span class="text-danger"><?php echo form_error('email'); ?></span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="subject" class="control-label">Subject</label>
</div>
<div class="col-md-12">
<input class="form-control" name="subject" placeholder="Your Subject" type="text" value="<?php echo set_value('subject'); ?>" />
<span class="text-danger"><?php echo form_error('subject'); ?></span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="message" class="control-label">Message</label>
</div>
<div class="col-md-12">
<textarea class="form-control" name="message" rows="4" placeholder="Your Message"><?php echo set_value('message'); ?></textarea>
<span class="text-danger"><?php echo form_error('message'); ?></span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input name="submit" type="submit" class="btn btn-primary" value="Send" />
</div>
</div>
</fieldset>
<?php echo form_close(); ?>
<?php echo $this->session->flashdata('msg'); ?>
</div>
</div>
</div>
This is my email.php in my config folder: (I don't know if I need this file because I have the same code in my controller)
<?php
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com'; //change this
$config['smtp_port'] = '465';
$config['smtp_user'] = 'xxxxxxxx#gmail.com';
$config['smtp_pass'] = 'xxxxxxxx';
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes to comply with RFC 822 standard
?>
you add email.php in config folder
<?php
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com'; //change this
$config['smtp_port'] = '465';
$config['smtp_user'] = 'xxxxxxxx#gmail.com';
$config['smtp_pass'] = 'xxxxxxxx';
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes to comply with RFC 822 standard
?>
then auto load config and library in autoload.php
$autoload['libraries'] = array('email');
$autoload['config'] = array('email');
and you send mail using this
$to_email = 'ferran1004#gmail.com';
$message = "email message";
$this->email->from('noreply#gmail.com','Admin');
$this->email->to($to_email);
$this->email->subject($subject);
$this->email->message($message);
if ($this->email->send() == TRUE)
{
log_message('debug', 'Email Send SuccessFully>>>>>>>>>>>');
}
else
{
log_message('debug', 'Email Not Send>>>>>>>>>>>>>>>');
}

How to send email without using SMTP protocol on website in codeigniter

I am creating contact us page in my website which is in CodeIgniter. I want to send this contact form data in my mail address.
How to send email in CodeIgniter without using SMTP for website?
yes you can use codeIgniter simple mail function.
Example:-
public function send_mail() {
$from_email = "your#example.com";
$to_email = $this->input->post('email');
//Load email library
$this->load->library('email');
$this->email->from($from_email, 'Your Name');
$this->email->to($to_email);
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
//Send mail
if($this->email->send())
$this->session->set_flashdata("email_sent","Email sent successfully.");
else
$this->session->set_flashdata("email_sent","Error in sending Email.");
$this->load->view('email_form');
}
You can send a email.
Controller.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Inquiry extends CI_Controller
{
public function inquiry()
{
parent::__construct();
/* Model */
}
public function index()
{
$this->load->view('header', array("title" => "Inquiry"));
$this->load->view('your_view',$view);
$this->load->view('footer');
}
function inviteStaff()
{
$this->load->library('email');
$from_email = $_POST['email'];
$to_email = "your#email.com";
$body='이름 : '.$_POST['name'].'<br /><br />email : '.$_POST['email'].'<br /><br />contents : '.$_POST['contents'].'';
$this->email->from($from_email, $_POST['name']);
$this->email->to($to_email);
$this->email->set_mailtype("html");
$this->email->subject('TITLE');
$this->email->message($body);
$this->email->send();
}
function emailCheck()
{
$user_id = base64_decode($_POST['user_id']);
$email = $_POST['check_mail'];
$where = array('user_emailId' => $email,'user_id!=' => $user_id);
$view = $this->mdl_file->sel_where('user_details',$where);
echo count($view);
}
}
view.
<form class="form-horizontal form-label-left" method="POST" action="<?php echo base_url();?>Inquiry/inviteStaff">
<div class="item form-group" id="email_div">
<label class="control-label col-md-3 col-sm-3 col-xs-3 right" for="name">이름<span class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-6" >
<input type="text" id="name" name="name" required="required" class="form-control col-md-7 col-xs-12" placeholder="이름" onblur="return emailCheck();" value="<?php echo #$staff_details[0]['user_emailId'] ?>">
</div>
<div class="alert">Your Name.</div>
<div class="alert_1" style="position: absolute;margin-left: 735px;width: 160px;display: none;margin-top: 5px;color: red;">
</div>
</div>
<div class="item form-group" id="email_div">
<label class="control-label col-md-3 col-sm-3 col-xs-3 right" for="email">E-mail<span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-6" >
<input type="text" id="email" name="email" required="required" class="form-control col-md-7 col-xs-12" placeholder="Email" onblur="return emailCheck();" value="<?php echo #$staff_details[0]['user_emailId'] ?>">
</div>
<div class="alert">Your Email.</div>
<div class="alert_1" style="position: absolute;margin-left: 735px;width: 160px;display: none;margin-top: 5px;color: red;">
</div>
</div>
<div class="item form-group" id="email_div">
<label class="control-label col-md-3 col-sm-3 col-xs-3 right" for="contents">내용<span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-6" >
<textarea id="contents" name="contents" required="required" class="form-control col-md-7 col-xs-12" placeholder="내용" onblur="return emailCheck();" value="<?php echo #$staff_details[0]['user_emailId'] ?>" style="height:200px">
</textarea>
</div>
<div class="alert">Contents.</div>
<div class="alert_1" style="position: absolute;margin-left: 735px;width: 160px;display: none;margin-top: 5px;color: red;">
</div>
</div>
</form>

Need help creating registration/login form in CodeIgniter

So that we're on the same page, I'm following along with this tutorial:
http://www.kodingmadesimple.com/2015/08/create-simple-registration-form-codeigniter-email-verification.html
Besides the starting CodeIgniter files, above is exactly what my code looks like. But here it is for those who can't view the link:
I have the model:
<?php
class user_model extends CI_Model
{
function __construct()
{
// Call the Model constructor
parent::__construct();
}
//insert into user table
function insertUser($data)
{
return $this->db->insert('user', $data);
}
//send verification email to user's email id
function sendEmail($to_email)
{
$from_email = 'team#mydomain.com'; //change this to yours
$subject = 'Verify Your Email Address';
$message = 'Dear User,<br /><br />Please click on the below activation link to verify your email address.<br /><br /> http://www.example.com/user/verify/' . md5($to_email) . '<br /><br /><br />Thanks<br />Mydomain Team';
//configure email settings
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.mydomain.com'; //smtp host name
$config['smtp_port'] = '465'; //smtp port number
$config['smtp_user'] = $from_email;
$config['smtp_pass'] = '********'; //$from_email password
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes
$this->email->initialize($config);
//send mail
$this->email->from($from_email, 'Mydomain');
$this->email->to($to_email);
$this->email->subject($subject);
$this->email->message($message);
return $this->email->send();
}
//activate user account
function verifyEmailID($key)
{
$data = array('status' => 1);
$this->db->where('md5(email)', $key);
return $this->db->update('user', $data);
}
}
?>
The Controller:
<?php
class user extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper(array('form','url'));
$this->load->library(array('session', 'form_validation', 'email'));
$this->load->database();
$this->load->model('user_model');
}
function index()
{
$this->register();
}
function register()
{
//set validation rules
$this->form_validation->set_rules('fname', 'First Name', 'trim|required|alpha|min_length[3]|max_length[30]|xss_clean');
$this->form_validation->set_rules('lname', 'Last Name', 'trim|required|alpha|min_length[3]|max_length[30]|xss_clean');
$this->form_validation->set_rules('email', 'Email ID', 'trim|required|valid_email|is_unique[user.email]');
$this->form_validation->set_rules('password', 'Password', 'trim|required|matches[cpassword]|md5');
$this->form_validation->set_rules('cpassword', 'Confirm Password', 'trim|required');
//validate form input
if ($this->form_validation->run() == FALSE)
{
// fails
$this->load->view('user_registration_view');
}
else
{
//insert the user registration details into database
$data = array(
'fname' => $this->input->post('fname'),
'lname' => $this->input->post('lname'),
'email' => $this->input->post('email'),
'password' => $this->input->post('password')
);
// insert form data into database
if ($this->user_model->insertUser($data))
{
// send email
if ($this->user_model->sendEmail($this->input->post('email')))
{
// successfully sent mail
$this->session->set_flashdata('msg','<div class="alert alert-success text-center">You are Successfully Registered! Please confirm the mail sent to your Email-ID!!!</div>');
redirect('user/register');
}
else
{
// error
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Oops! Error. Please try again later!!!</div>');
redirect('user/register');
}
}
else
{
// error
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Oops! Error. Please try again later!!!</div>');
redirect('user/register');
}
}
}
function verify($hash=NULL)
{
if ($this->user_model->verifyEmailID($hash))
{
$this->session->set_flashdata('verify_msg','<div class="alert alert-success text-center">Your Email Address is successfully verified! Please login to access your account!</div>');
redirect('user/register');
}
else
{
$this->session->set_flashdata('verify_msg','<div class="alert alert-danger text-center">Sorry! There is error verifying your Email Address!</div>');
redirect('user/register');
}
}
}
?>
And the View:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CodeIgniter User Registration Form Demo</title>
<link href="<?php echo base_url("bootstrap/css/bootstrap.css"); ?>" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<?php echo $this->session->flashdata('verify_msg'); ?>
</div>
</div>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-default">
<div class="panel-heading">
<h4>User Registration Form</h4>
</div>
<div class="panel-body">
<?php $attributes = array("name" => "registrationform");
echo form_open("user/register", $attributes);?>
<div class="form-group">
<label for="name">First Name</label>
<input class="form-control" name="fname" placeholder="Your First Name" type="text" value="<?php echo set_value('fname'); ?>" />
<span class="text-danger"><?php echo form_error('fname'); ?></span>
</div>
<div class="form-group">
<label for="name">Last Name</label>
<input class="form-control" name="lname" placeholder="Last Name" type="text" value="<?php echo set_value('lname'); ?>" />
<span class="text-danger"><?php echo form_error('lname'); ?></span>
</div>
<div class="form-group">
<label for="email">Email ID</label>
<input class="form-control" name="email" placeholder="Email-ID" type="text" value="<?php echo set_value('email'); ?>" />
<span class="text-danger"><?php echo form_error('email'); ?></span>
</div>
<div class="form-group">
<label for="subject">Password</label>
<input class="form-control" name="password" placeholder="Password" type="password" />
<span class="text-danger"><?php echo form_error('password'); ?></span>
</div>
<div class="form-group">
<label for="subject">Confirm Password</label>
<input class="form-control" name="cpassword" placeholder="Confirm Password" type="password" />
<span class="text-danger"><?php echo form_error('cpassword'); ?></span>
</div>
<div class="form-group">
<button name="submit" type="submit" class="btn btn-default">Signup</button>
<button name="cancel" type="reset" class="btn btn-default">Cancel</button>
</div>
<?php echo form_close(); ?>
<?php echo $this->session->flashdata('msg'); ?>
</div>
</div>
</div>
</div>
</div>
</body>
I've set up my database in mySQL and my form comes out just fine when connecting to my local server.
But upon filling out the form and hitting "Sign Up" I hit this error in Safari:
Any idea what could be causing this and how to fix it?
If your using codeigniter 3
You have your base url blank and that is why ::1 you can leave it blank will work most of the time but you may run it to error.
$config['base_url'] = '';
Set your base url.
$config['base_url'] = 'http://localhost/project/';
Or A Live Domain Example
$config['base_url'] = 'http://www.example.com/';
Update:
Check your controllers etc make sure your file name has first letter upper case and same with class. Example: User.php and class User extends CI_Controller {}

I can't get this form to work either from localhost or online using codeigniter

I have the Contact Me form that I can't get to send me an email. I am still a newbie but I don't see anything wrong. Help me out guys.
Here's the contactform controller
<?php
class contactform extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper(array('form','url'));
$this->load->library(array('session', 'form_validation', 'email'));
}
function index() {
//set validation rules
$this->form_validation->set_rules('name', 'Name', 'trim|required|xss_clean|callback_alpha_space_only');
$this->form_validation->set_rules('email', 'Emaid ID', 'trim|required|valid_email');
$this->form_validation->set_rules('subject', 'Subject', 'trim|required|xss_clean');
$this->form_validation->set_rules('message', 'Message', 'trim|required|xss_clean');
//run validation on form input
if ($this->form_validation->run() == FALSE) {
//validation fails
//$this->load->view('contact_view');
$this->load->view('header_view');
$this->load->view('nav_view');
$this->load->view('contact_view');
$this->load->view('footer_view');
}
else {
//get the form data
$name = $this->input->post('name');
$from_email = $this->input->post('email');
$subject = $this->input->post('subject');
$message = $this->input->post('message');
//set to_email id to which you want to receive mails
$to_email = 'mygmail#gmail.com';
//configure email settings
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_user'] = 'mygmail#gmail.com';
$config['smtp_pass'] = 'mypass';
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes
//$this->load->library('email', $config);
$this->email->initialize($config);
//send mail
$this->email->from($from_email, $name);
$this->email->to($to_email);
$this->email->subject($subject);
$this->email->message($message);
if ($this->email->send())
{
// mail sent
$this->session->set_flashdata('msg','<div class="alert alert-success text-center">Your mail has been sent successfully!</div>');
redirect('contactform/index');
}
else
{
//error
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">There is error in sending mail! Please try again later</div>');
redirect('contactform/index');
}
}
}
//custom validation function to accept only alphabets and space input
function alpha_space_only($str) {
if (!preg_match("/^[a-zA-Z ]+$/",$str)) {
$this->form_validation->set_message('alpha_space_only', 'The %s field must contain only alphabets and space');
return FALSE;
}
else {
return TRUE;
}
}
}
?>
and here is my contact_view
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3 well">
<?php $attributes = array("class" => "form-horizontal", "name" => "contactform");
echo form_open("contactform/index", $attributes);?>
<fieldset>
<legend>Contact Form</legend>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Name</label>
</div>
<div class="col-md-12">
<input class="form-control" name="name" placeholder="Your Full Name" type="text" value="<?php echo set_value('name'); ?>" />
<span class="text-danger"><?php echo form_error('name'); ?></span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="email" class="control-label">Email ID</label>
</div>
<div class="col-md-12">
<input class="form-control" name="email" placeholder="Your Email ID" type="text" value="<?php echo set_value('email'); ?>" />
<span class="text-danger"><?php echo form_error('email'); ?></span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="subject" class="control-label">Subject</label>
</div>
<div class="col-md-12">
<input class="form-control" name="subject" placeholder="Your Subject" type="text" value="<?php echo set_value('subject'); ?>" />
<span class="text-danger"><?php echo form_error('subject'); ?></span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="message" class="control-label">Message</label>
</div>
<div class="col-md-12">
<textarea class="form-control" name="message" rows="4" placeholder="Your Message"><?php echo set_value('message'); ?></textarea>
<span class="text-danger"><?php echo form_error('message'); ?></span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input name="submit" type="submit" class="btn btn-primary" value="Send" />
</div>
</div>
</fieldset>
<?php echo form_close(); ?>
<?php echo $this->session->flashdata('msg'); ?>
</div>
</div>
I already checked my codes. But the problem is, I can't see why it cant send. I even tried to upload it to my website, but it still won't let me send an email.

Categories