0

I have some problems, meaning that I don't receive mail from a form...

the code looks like this:

public function send_email(){
        $this->load->library("form_validation");


        $this->form_validation->set_rules("fullName", "Full Name", "required|alpha|xss_clean");
        $this->form_validation->set_rules("email", "Email Address", "required|valid_email|xss_clean");
        $this->form_validation->set_rules("message", "Message", "required|xss_clean");

            if($this->form_validation->run() == FALSE){
                $data["message"] = "";
                $this->load->view("site_header");
                $this->load->view("site_nav");
                $this->load->view("content_comment", $data);
                $this->load->view("site_footer");
            }else{
                $data["message"] = "The email was successfully been sent!";


                $this->load->library("email");


                $this->email->from(set_value("email"), set_value("fullName"));
                $this->email->to("paulharbuz@gmail.com");
                $this->email->subject("Message from our form");
                $this->email->message(set_value("message"));

                $this->email->send();

                echo $this->email->print_debugger();


                $this->load->view("site_header");
                $this->load->view("site_nav");
                $this->load->view("content_comment", $data);
                $this->load->view("site_footer");
            }
    }

And i get an error that looks like this:

Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.**

Is this from my php.ini file?

i've set my files reading this part on http://php.net/manual/en/ref.mail.php

i found the solution: create a file in config: email.php that looks like this

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| EMAIL CONFING
| -------------------------------------------------------------------
| Configuration of outgoing mail server.
| */

$config['wordwrap'] = FALSE;
$config['mailtype'] = 'html';
$config['crlf'] = '\r\n';
$config['charset']='utf-8';
$config['newline']="\r\n";
$config['priority']=1;
$config['protocol']='smtp';
$config['smtp_host']='ssl://smtp.googlemail.com';
$config['smtp_port']='465';
$config['smtp_timeout']='30';
$config['smtp_user']='gcc.sandbox@gmail.com';
$config['smtp_pass']='qwaszx12';
$config['newline']="\r\n";

/* End of file email.php */
/* Location: ./system/application/config/email.php */

then load this in your main controller like: $this->email->initialize($this->config->config); and that's it!

Cœur
  • 37,241
  • 25
  • 195
  • 267
emcee22
  • 1,851
  • 6
  • 23
  • 32
  • Look [here][1], maybe you can find the answer. [1]: http://stackoverflow.com/questions/3859958/codeigniter-unable-to-send-email-using-php-mail – BCsongor Jan 24 '13 at 08:50

3 Answers3

0
$string = 'mail content';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: z' . "\r\n";
mail(email, 'subject', $string, $headers);
Lucky13
  • 11,393
  • 7
  • 25
  • 36
0

simply add this code to you helper file and call the function when you want to send mail the following method to send an email...

 function send_mail($to,$subject,$message) {
    $config = Array(
        'protocol'  => 'smtp',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => 465,
        'smtp_user' => 'xxx@xxxx',
        'smtp_pass' => 'xxxx',
        'mailtype'  => 'html', 
        'charset'   => 'iso-8859-1'
    );
    $this->load->library('email',$config);
    $this->email->set_newline("\r\n");

    $this->email->from($config['smtp_user'],"Your name");
    $this->email->to($to);
    $this->email->subject($subject);  
    $this->email->message($message);
    $result = $this->email->send();
    return $result;
}
Jitesh Tukadiya
  • 1,269
  • 1
  • 11
  • 25
0

I want to add little more knowledge into it if you are using gmail so this cannot be done by your own password it can be done by using specific Google password . if you get error like require application-specific password. than search it in Google and get one and type in the field below as i did. $config['smtp_pass']='application-specific password';

syed shah
  • 678
  • 1
  • 6
  • 22