Welcome Guest, Not a member yet? Register   Sign In
unable to send email
#1

[eluser]ashutosh[/eluser]
Hi ,

i am trying to send email from my localhost. I am using xampp, And also i have enalble Mercury

After submiting the form i am getting the Success message ,but i am not seeing any email in my inbox/spam.

Pelase help me to solve my problem.


My code:

Code:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class contact extends CI_Controller  {
    public function __construct()
    {
        parent:: __construct();
        $this->load->helper('url');
        $this->load->helper('form');
        $this->load->library('session');
        $this->load->library('email');
        $this->load->model('shopmodel');
        $this->load->model('contactusmodel');
        $this->load->library('form_validation');
    }
    
    function index()
    {
         $this->form_validation->set_error_delimiters(' <li  class="errorlist">', '</li>')->set_rules('fullname', 'Name','trim|required|min_length[5]|max_length[50]|xss_clean');
         $this->form_validation->set_error_delimiters('<li  class="errorlist">', '</li>')->set_rules('countryname', 'Country','trim|required|min_length[2]|max_length[50]|xss_clean');
         $this->form_validation->set_error_delimiters('<li  class="errorlist">', '</li>')->set_rules('email', 'Email', 'trim|required|valid_email');
         $this->form_validation->set_error_delimiters('<li  class="errorlist">', '</li>')->set_rules('contactdetails', 'Contact Details','trim|required|min_length[40]|max_length[2000]|xss_clean');
         $data=$this->contactusmodel->contactusmodel();
         $data["query"] = $this->shopmodel->getshopdetailsById(199);//taking data as shop id 199
          
          if($this->form_validation->run() === FALSE)
          {  
                $data['ffullname']['value'] = $this->input->post('fullname');
                $data['fcountryname']['value'] =$this->input->post('email');
                $data['femail']['value'] = $this->input->post('countryname');
                $data['fcontactdetails']['value'] =$this->input->post('contactdetails');
                $this->load->view('contact/contact',$data);  
          }
          
          else if ($this->form_validation->run() === TRUE)
          {
              $name=$this->input->post('fullname');
              $sendersemail=$this->input->post('email');
              $fromcountry=$this->input->post('countryname');
              $message=$this->input->post('contactdetails');
              
              $config = Array(
                'protocol' => 'smtp',
                        'smtp_host' => 'ssl://smtp.googlemail.com',
                        'smtp_port' => 465,
                        'smtp_user' => '[email protected]',
                        'smtp_pass' => '234abcd323#',
                        'mailtype'  => 'html',
                        'charset' => 'utf-8',
                        'wordwrap' => TRUE

             );
              
               $this->load->library('email', $config);
               $this->email->set_mailtype("html");
                $this->email->set_newline("\r\n");
                $email_body ="<div>hello world</div>";
                $this->email->from('[email protected]', 'ddd');

                $list = array('[email protected]');
                $this->email->to($list);
                $this->email->subject('Testing Email');
                $this->email->message($email_body);

                $this->email->send();
                echo $this->email->print_debugger();
          }
          else{
              $this->load->view('contact/contact',$data);  
          }
    }
}

?&gt;

What output i am getting is:

Code:
Your message has been successfully sent using the following protocol: mail
From: "ddd"
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: multipart/alternative; boundary="B_ALT_513e1456185e3"


=?utf-8?Q?Testing_Email?=
This is a multi-part message in MIME format.
Your email application may not support this format.

--B_ALT_513e1456185e3
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

hello world


--B_ALT_513e1456185e3
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<div>hello world</div>

--B_ALT_513e1456185e3--
#2

[eluser]TheFuzzy0ne[/eluser]
First of all, I would remove your email address from the post above. Smile

Secondly, you might want to consider using an SMTP mail account for sending mail. All the configuration is done. All you need to do is use it. On top of that, if something is not right, you can see straight away.
#3

[eluser]ashutosh[/eluser]
Its very difficult.
How can i send email using an SMTP mail account ?
Please check and help me why my above code is not sending email?

I will remove my email once my above problem is fixed.

Please help.
#4

[eluser]ashutosh[/eluser]
Please reply.
#5

[eluser]TheFuzzy0ne[/eluser]
When you signed up for Internet, your ISP probably provided you with an email address, and they'll no doubt have an SMTP server that you can use.

Sending using SMTP is simple once you have the correct settings. You just put them into ./application/config/email.php, and they'll be automatically loaded whenever you load the email library.

If you're going to send via GMail, you may need to generate an application-specific password, but I suspect you're still going to run into more problems.
#6

[eluser]TheFuzzy0ne[/eluser]
You're also running validation twice.

You should have:
Code:
if ($this->form_validation->run() === TRUE) {
     // Validation passed
} else {
     // Validation failed
}

In order for you to get this working, the SSL PHP extension must be loaded. Do you know if it is?
#7

[eluser]ashutosh[/eluser]
Well i would like to use this technique.

"Sending using SMTP is simple once you have the correct settings. You just put them into ./application/config/email.php, and they’ll be automatically loaded whenever you load the email library."


I checked my ./application/config/ folder , there is no any email.php file . I am using codeigniter 2. I am seeing Email.php file into folder system/libraries/Email.php

Now how can i correct my setting . There is no any email.php into my config folder?
#8

[eluser]TheFuzzy0ne[/eluser]
That's not the key to fixing this. It's simply a way of keeping your settings out of your controller so they can easily be re-used in other places in your app.

You still haven't answered the question. Is the SLL PHP extension enabled?

Why can't you use the email account your ISP probably supplied you with when you signed up for your Internet?
#9

[eluser]ashutosh[/eluser]
I am testing on my live server. There will be SLL PHP extension enabled , i guess.

What do you mean by "Why can’t you use the email account your ISP probably supplied you with when you signed up for your Internet?"

Please describe its meaning!

#10

[eluser]TheFuzzy0ne[/eluser]
I have ADSL Broadband provided by Sky - a British company. They have provided me with an email address to use. The service allows me to connect to their server to send emails using SMTP.

Who provides your Internet connection? I'm assuming yours works in a similar way.




Theme © iAndrew 2016 - Forum software by © MyBB