0

I am trying to send simple email using codeigniter as explain this link codeigniter email class ,but it doesn't work. This is my form :

<form method="post" action="<?php base_url()?>main/send_email">
               <input type="text" placeholder="Name" name="name" class="name">
               <input type="text" placeholder="Surname" name="surname" class="surname">
               <input type="email" placeholder="email" name="email" class="email">
               <textarea placeholder="What's on your mind" name="text" class="text"></textarea>
               <input type="submit" value="SEND" class="send_mail" name="send_mail">
</form>

And this is my controller

  <?php
    defined('BASEPATH') OR exit('No direct script access allowed');

   class Main extends CI_Controller {
     public function __construct(){
     parent::__construct();
     $this->load->helper("common_helper");

    date_default_timezone_set('Asia/Tbilisi');
 }

public function index()
{

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

public function send_email()
{
    $this->load->library("email");
    if($this->input->post("send_mail"))
    {
        $name = $this->input->post("name");
        $surname = $this->input->post("surname");
        $email = $this->input->post("email");
        $text = $this->input->post("text");
         $this->email->from($email, $name);
         $this->email->to('77vanich77@gmail.com');
         $this->email->subject('Email Test');
         $this->email->message('testing email message');

         $this->email->send();
    }


 }
}

I don't have any error.

riya
  • 116
  • 15
Vano
  • 690
  • 3
  • 8
  • 25
  • if using localhost http://stackoverflow.com/questions/19132171/send-email-from-localhost-running-xammp-in-php-using-gmail-mail-server – Abhishek Gurjar Jul 26 '16 at 07:02
  • simple mail function wont work in localhost. Try using smtp mail to send email from localhost. Click [here](http://www.codeigniter.com/user_guide/libraries/email.html) for documentaion –  Jul 26 '16 at 07:06
  • Sorry,it's strange but it's working now,thanks anyway :) – Vano Jul 26 '16 at 07:10
  • What are you using wamp or xampp? –  Jul 26 '16 at 07:24
  • @wolfgang1983 its working now,thank you for attention :) – Vano Jul 26 '16 at 09:00

1 Answers1

1

Try the below code.

$email_config = Array(
             'protocol'  => 'smtp',
             'smtp_host' => 'bh-24.webhostbox.net',
             'smtp_port' => '465',
             'smtp_user' => 'feedback@domain.com',
             'smtp_pass' => '12feedback34',
             'mailtype'  => 'html',
             'starttls'  => true,
             'newline'   => "\r\n"
             );
                $this->load->library('email', $email_config);
                $this->email->from($to, 'FEEDBACK');
                $this->email->to('feedback@domain.com');
                $this->email->subject($sub);
                $this->email->message($msg);
                $this->email->send();
  • I have found the article which demonstrate how to send emails in a CodeIgniter application using SMTP. https://www.cloudways.com/blog/send-email-codeigniter-smtp/ – Owais Alam Aug 23 '17 at 13:13