1

Hello i need help i have been doing my best to be able to send html email but its not working i just get the alert that email have not been sent. In the library > email.php file i havent change anything just left as default please help because i have been trying to solve this problem since two weeks ago please help!

        $name = $this->input->post('name');

        $email = $this->input->post('email');

        $comment = $this->input->post('message');

        $config['mailtype'] = 'html';

        $this->load->library('email',$config);

        $message =  "<html>";

        $message .= "<style type='text/css'> body,td,th { font-family: Arial, Helvetica, sans-serif; font-size: 13px;}</style>";

        $message .=  "<body>";

        $message .= "<table width='650' border='1' cellspacing='0' cellpadding='6'> ";

        $message .= "<tr>";

        $message .= "<td colspan='2' bgcolor='#6495ed' style='font-weight: bold;'>CONTACT DETAILS</td>";

        $message .= "</tr>";

        $message .= "<tr>";

        $message .= "<td width='237'>Client Name:</td>"."<td width='393'>".$name."</td>";


        $message .= "</tr>";

        $message .=  "<tr>";

        $message .=  "<td>Message:</td>"."<td>".$comment."</td>";

        $message .= "</table><br><br>";

        $message .= "</body>";

        $message .= "</html>";



        $this->email->from($email,$name);

        $this->email->to('fredma@gmail.com','nfy@layeaketz.com');

        $this->email->subject('New Contact Email from Client');

        $this->email->message($message);

        $this->email->send();

        if($this->email->send()== TRUE){
            echo'message sent';
        }else{
            echo'message not sent';

        }
user3551487
  • 162
  • 2
  • 3
  • 15
  • I only see this `$config['mailtype'] = 'html';` have you got smtp host etc as shows in user guide? http://www.codeigniter.com/user_guide/libraries/email.html#setting-email-preferences-in-a-config-file –  Nov 10 '15 at 09:49
  • check after adding this `$config['charset'] = 'utf'; $config['wordwrap'] = 'TRUE';` – Prafulla Nov 10 '15 at 09:49
  • Thanks let me edit then will give you a feedback – user3551487 Nov 10 '15 at 09:52
  • Did you receive this emails ? – kirugan Nov 10 '15 at 09:52
  • Thanks but i get this error......... Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() – user3551487 Nov 10 '15 at 09:55
  • i haven't received any email – user3551487 Nov 10 '15 at 09:57
  • If your working on a local host you may need to configure the sendmail features that comes with that local host https://www.youtube.com/watch?v=TO7MfDcM-Ho –  Nov 10 '15 at 11:20

2 Answers2

1

Because you are sending email two times in your code

$this->email->send();// first time

if($this->email->send()== TRUE){ //and second time here

After $this->email->send() every thing is clear. Just use

$this->email->message($message);
        if($this->email->send()== TRUE){
            echo'message sent';
        }else{
            echo'message not sent';
        }
Saty
  • 22,443
  • 7
  • 33
  • 51
1

Send mail with googlemail smtp

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

$config = Array(   
        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => 465,
        'smtp_user' => 'abc@gmail.com', // change it to yours
        'smtp_pass' => '*******', // change it to yours
        'mailtype' => 'html', // text
        'charset' => 'iso-8859-1',
        'newline' => '\r\n',
        'wordwrap' => TRUE
    );

    $this->email->initialize($config);
    $this->email->from('abc@gmail.com'); 
    $this->email->to('test@gmail.com');

    $this->email->subject('Test mail');
    $this->email->message('Test HTML Data');
    if($this->email->send())
    {

        echo "Mail sent";
    }
    else
    {
        show_error($this->email->print_debugger());
    }
Arvind Jaiswal
  • 442
  • 5
  • 14