Welcome Guest, Not a member yet? Register   Sign In
Trouble with html email
#1

[eluser]TheoR74[/eluser]
Here is my mail settings:
Code:
$this->load->library('email');
        $config['mailtype'] = 'html' ;
        $config['protocall'] = "smtp";
        $config['smtp_host'] = "mail.smtp.com ";
        $config['smtp_user'] = "[email protected]";
        $config['smtp_pass'] = "test";
        $config['smtp_port'] = "587";
        $config['smtp_timeout'] = 300;
        
        
        $this->email->initialize($config);        
        $this->email->from('[email protected]', 'Test');
        $this->email->to($email);
        
        $this->email->subject('Test Subject');
        $this->email->message('Test Message');
        
        $this->email->send();

This produces this error:
Quote:Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.

However, if I change mailtype to "text", then it works.

Please help....
#2

[eluser]Tom Glover[/eluser]
This works, just need to set your SMTP settings if on windows or leave it as it is, if it doesn't work on *nix try "send mail" or "php mail" or "SMTP" as the protocol. SMTP will work which ever server.

Controller for email sending:
Code:
function index()
    {        
        
        $form['state']        = "1";
        $data['content']    = $this->load->view('contact',$form,true);
        $data['pageTitle']  = 'Contact us';
        $data['introText']  = "Below are way in how to contact us at ******.com";
        $this->load->view('template',$data);        
    }
    function send(){
    
        $this->load->helper(array('form'));
            
        $rules['name']        = "required|encode_php_tags|xxs_clean";
        $rules['email']        = "required|valid_email";
        $rules['tel']        = "required|numeric";
        $rules['subject']    = "required|encode_php_tags|xxs_clean";
        $rules['message']    = "required|encode_php_tags|xxs_clean";
        
        $this->validation->set_rules($rules);
        
        
        if ($this->validation->run() == FALSE)
        {
            $form['state']        = "1";
            $data['content'] = $this->load->view('contact',$form,true);
            $data['pageTitle'] = 'Contact us';
            $data['introText'] = "Below are way in how to contact us at ******.com";
            $this->load->view('template',$data);
        }
        else
        {
            $form['state']        = "2";
            $data['content'] = $this->load->view('contact',$form,true);
            $data['pageTitle'] = 'Contact us';
            $data['introText'] = "Below are way in how to contact us at ******.com";
            $this->load->view('template',$data);
            
            //Write and Send Email//
            $this->load->library('email');
            /*$config['smtp_host'] = '**********************';
            $config['smtp_user'] = '******************';
            $config['smtp_pass'] = '******';*/
            $config['protocol'] = 'sendmail';
            $config['useragent'] = 'WebSite - ************';
            $config['mailtype'] = 'html';
            
            $this->email->initialize($config);
            
            $this->email->from('***************', '***********');
            $this->email->reply_to($_POST['email'], $_POST['name']);
            $this->email->to('*******************');
            if ($_POST['copyEmail'] == 1){
                $this->email->cc($_POST['email']);
                $message['clientCopy'] = 'Email copied to client.';
            }
            $this->email->subject($_POST['subject'].' - Web-Site Form');
            //construct the messsage//
                $message['name']        = $_POST['name'];
                $message['tel']        = $_POST['tel'];
                $message['email']       = $_POST['email'];
                $message['subject']    = $_POST['subject'];
                $message['message']    = $_POST['message'];
                $message['clientCopy'] = 'Email copied to client.';
            //output message as var//
                   $this->email->message($this->load->view('email',$message,true)); // creates and loads view, instead of outputting it sends code.
            
            // Send email
            $this->email->send();
            
            //Uncoment Below for Debugger//
             //echo $this->email->print_debugger();
        }
View file of the email html:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;&lt;style type="text/css">
&lt;!--
body,td,th {
    color: #FFFFFF;
}
body {
    background-color: #996633;
}
h1{
    font-size: 16px;
    font-weight: bold;
    color: #FFFFFF;
    border-bottom: medium solid #FFFFFF;
}
--&gt;
&lt;/style&gt;
&lt;body&gt;
<div id="content">
<h1>Web Form Inquiry</h1>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20%" valign="middle"><div align="right"><strong>Full Name: </strong></div></td>
<td width="335" valign="middle">&lt;?php echo $name?&gt;</td>
</tr>
<tr>
<td valign="middle"><div align="right"><strong>Email:</strong></div></td>
<td valign="middle">&lt;?php echo $email?&gt;</td>
</tr>
<tr>
<td valign="middle"><div align="right"><strong>Telephone:</strong></div></td>
<td valign="middle">&lt;?php echo $tel?&gt;</td>
</tr>
<tr>
<td valign="middle"><div align="right"><strong>Subject:</strong></div></td>
<td valign="middle">&lt;?php echo $subject?&gt;</td>
</tr>
<tr>
<td height="60" valign="middle"><div align="right"><strong>Message:</strong></div></td>
<td width="80%" valign="middle">&lt;?php echo $message?&gt;</td>
</tr>
<tr>
<td colspan="2" valign="middle">&lt;?php echo $clientCopy ?&gt;</td>
</tr>
</table>
<p>&nbsp;</p></div>
&lt;/body&gt;
&lt;/html&gt;
#3

[eluser]Unknown[/eluser]
same problem
#4

[eluser]mi6crazyheart[/eluser]
Use this piece of code.....
Code:
$this->load->library('email');
        $this->email->clear();
        $config['mailtype'] = 'html' ;
        $config['protocall'] = "smtp";
        $config['smtp_host'] = "mail.smtp.com ";
        $config['smtp_user'] = "[email protected]";
        $config['smtp_pass'] = "test";
        $config['smtp_port'] = "587";
        $config['smtp_timeout'] = 300;
        
        
        $this->email->initialize($config);        
        $this->email->from('[email protected]', 'Test');
        $this->email->to($email);
        
        $this->email->subject('Test Subject');
        $this->email->message('Test Message');
        
        $this->email->send();
#5

[eluser]Ivar89[/eluser]
shouldn't it be
Code:
$config['protocol'] = "smtp";
instead of:
Code:
$config['protocall'] = "smtp";
.....




Theme © iAndrew 2016 - Forum software by © MyBB