0

i have a problem in sending email in codeigniter.

$ci = get_instance();
$ci->load->library('email');
$config['protocol'] = "mail";
$config['smtp_host'] = "ssl://mail.smsgt.com";
$config['smtp_port'] = "25";
$config['smtp_user'] = "myemail@smsgt.com"; 
$config['smtp_pass'] = "";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['newline'] = "\r\n";
$config['crlf'] = "\r\n";

and here is my code when sending the email

public function send_email_accountability($C11,$C12)
{

    date_default_timezone_set('Asia/Manila');
    $this->load->library('email');
    $this->email->set_mailtype("html");
    $this->email->from('noreply@smsgt.com', 'company email');
    $this->email->to($C11); 
    $this->email->subject('Accountability for'. " ". $C12);
    $this->email->message("testing");

    $check = $this->email->send();
    //echo $this->email->print_debugger(); 
    if ($check){
                $data = "true";
    }
            else{
                $data = "false";
            }

}

when i'm sending email with plain text in MESSAGE it works fine. but the problem is when i'm sending email with HTML scripts, it will not produce error but it will not send to the user and the email will not be received using MS OUTLOOK. can someone help me with this problem? thanks guys !

Vincent
  • 852
  • 6
  • 29
  • 67

6 Answers6

0

Try adding this:

$this->email->priority(3);

You can find more information here: http://ellislab.com/codeigniter/user-guide/libraries/email.html

Walter Caraza
  • 911
  • 1
  • 10
  • 19
0

You haven't initialize your email library with config values that you have set.

You just need to add below line in your code.

$this->email->initialize($config);
Snehal S
  • 865
  • 4
  • 13
  • 1
    i forgot to include $this->email->initialize($config); my problem is now it slow to be received by the user. any details for this ? – Vincent Jan 29 '14 at 04:50
  • @vincent can you please explain your problem in brief? – Snehal S Jan 29 '14 at 04:59
  • @Shenal S my problem is that when i include an image in sending. the email will not sent at all. but when i didn't include the email. my email will be sent. and it usually takes 2-5mins to be sent – Vincent Jan 29 '14 at 05:05
  • @vincent all you need is config with protocol as 'mail' and mailtype as 'html' – Snehal S Jan 29 '14 at 05:11
0
public function send_email_accountability($C11,$C12)
{

    date_default_timezone_set('Asia/Manila');
    $this->load->library('email');
    $config['protocol'] = 'sendmail';
    $config['mailpath'] = '/usr/sbin/sendmail';
    $config['charset'] = 'utf-8';
    $config['wordwrap'] = TRUE;
    $config['mailtype'] = 'html';
    $this->email->initialize($config);
    //$this->email->set_mailtype("html");
    $this->email->from('noreply@smsgt.com', 'company email');
    $this->email->to($C11); 
    $this->email->subject('Accountability for'. " ". $C12);
    $this->email->message("testing");

    $check = $this->email->send();
    //echo $this->email->print_debugger(); 
    if ($check){
                $data = "true";
    }
            else{
                $data = "false";
            }

}
0

It would help if you can provide the possible error being returned by echo $this->email->print_debugger();, so why not just enable it at the moment then run your current code.

Alternatively, try this:

public function send_email_accountability($C11,$C12)
{
  date_default_timezone_set('Asia/Manila');

  $ci =& get_instance();
  $ci->load->library('email');

  $config['protocol'] = "mail";
  $config['smtp_host'] = "ssl://mail.smsgt.com";
  $config['smtp_port'] = "25";
  $config['smtp_user'] = "myemail@smsgt.com"; 
  $config['smtp_pass'] = "";
  $config['charset'] = "utf-8";
  $config['mailtype'] = "html";
  $config['newline'] = "\r\n";
  $config['crlf'] = "\r\n";

  $ci->email->initialize($config);

  $ci->email->from('noreply@smsgt.com', 'company email');
  $ci->email->to($C11); 
  $ci->email->subject('Accountability for'. " ". $C12);
  $ci->email->message("testing");

  $check = $ci->email->send();

  //echo $ci->email->print_debugger(); 

  if ($check)
    $data = "true";
  else
    $data = "false";    
}

EDIT

Since you mentioned on comment that the echo $ci->email->print_debugger(); returns "Your message has been successfully sent using the following protocol" it just simply means that there is no syntactically wrong in your script. Like I said, my thoughts would be mail server issue.

If I will suggest this will be how I will be debugging your issue:

  • I'll replace $C11 with a Gmail address in $ci->email->to($C11); then run my current script and see if the issue of delay is the same.
  • Replace your current SMTP server credentials with something like Mandrill as sure its reporting log will definitely give you a hint of what is happening.

But either way, I guess you'll still end up digging something on your mail server (@smsgt.com). If I were you, I will reach out to your server administrator and start looking for clues in the mail server logs.

missing_one
  • 186
  • 1
  • 11
  • Your message has been successfully sent using the following protocol: mail, that is the message i get. my problem is now it slow to be received by the user. any details for this ? – Vincent Jan 29 '14 at 04:52
  • 1
    $ci =& get_instance(); is there a & sign for get instance ? – Vincent Jan 29 '14 at 04:54
  • 1
    Yes that is `&`. My thoughts would be mail server issue. Have you tried sending it on another email other than **@smsgt.com**? – missing_one Jan 29 '14 at 06:03
  • i need to send all the emails to @smsgt.com because that is for the default email. the smtp port is 25. – Vincent Jan 29 '14 at 06:07
  • i also want to ask if what is the value of & in get_instance ? thanks – Vincent Jan 29 '14 at 06:09
  • 1
    `=&` is a passing a variable by reference, regarding the `$ci =& get_instance();` Anthony explains this well [here](http://stackoverflow.com/questions/4740430/explain-ci-get-instance). I did suggest to send it other than the **@smsgt.com** for you to assess whether if it is really the cause of your mail server (incoming) or (outgoing). – missing_one Jan 29 '14 at 06:23
  • your code works well but my only problem is now is how to improve the sending of emails to the users. can you help me out ? i tried sending it to @yahoo.com and it is also the problem. – Vincent Jan 29 '14 at 06:31
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/46300/discussion-between-vincent-and-dqlopez) – Vincent Jan 29 '14 at 06:48
0

Use something like this

    $this->load->library('email', array(
                    'protocol' => 'mail',
                    'smtp_host' => 'ssl://mail.smsgt.com',
                    'smtp_port' => '25',
                    'smtp_user' => 'myemail@smsgt.com',
                    'smtp_pass' => '',
                    'newline' => '\r\n',
                    'crlf' => '\r\n',
                    'mailtype' => 'html'
        ));

    $this->email->to($C11);
    $this->email->from('noreply@smsgt.com', 'company email');
    $this->email->subject('Accountability for'. " ". $C12);
    $this->email->message("testing");

    if( $this->email->send() ) {
        return TRUE;
    } else {
        return FALSE;
    }
Agha Umair Ahmed
  • 1,037
  • 7
  • 12
0

try this code here's my code i use in sending email

    function emailformat(){
            $config['protocol'] = 'smtp'; // mail, sendmail, or smtp    The mail sending protocol.
            $config['smtp_host'] = 'smtp.gmail.com'; // SMTP Server Address.
            $config['smtp_user'] = 'test@yahoo.com.ph'; // SMTP Username.
            $config['smtp_pass'] = '@password'; // SMTP Password.
            $config['smtp_port'] = '25'; // SMTP Port.
            $config['smtp_timeout'] = '5'; // SMTP Timeout (in seconds).
            $config['wordwrap'] = TRUE; // TRUE or FALSE (boolean)    Enable word-wrap.
            $config['wrapchars'] = 76; // Character count to wrap at.
            $config['mailtype'] = 'html'; // text or html Type of mail. If you send HTML email you must send it as a complete web page. Make sure you don't have any relative links or relative image paths otherwise they will not work.
            $config['charset'] = 'utf-8'; // Character set (utf-8, iso-8859-1, etc.).
            $config['validate'] = FALSE; // TRUE or FALSE (boolean)    Whether to validate the email address.
            $config['priority'] = 3; // 1, 2, 3, 4, 5    Email Priority. 1 = highest. 5 = lowest. 3 = normal.
            $config['crlf'] = "\r\n"; // "\r\n" or "\n" or "\r" Newline character. (Use "\r\n" to comply with RFC 822).
            $config['newline'] = "\r\n"; // "\r\n" or "\n" or "\r"    Newline character. (Use "\r\n" to comply with RFC 822).
            $config['bcc_batch_mode'] = FALSE; // TRUE or FALSE (boolean)    Enable BCC Batch Mode.
            $config['bcc_batch_size'] = 200; // Number of emails in each BCC batch.

                $this->load->library('email');
                $this->email->initialize($config);
                $this->email->from('test@yahoo.com.ph', 'Robot');
                $this->email->to('test@yahoo.com.ph');
                $this->email->subject('Expiration Notification');
                $this->email->message('<html><body>This Message is to notify!</body></html>');
                $this->email->send();
    }
Denmark
  • 538
  • 2
  • 8
  • 26