Tuesday, 14 February 2017

A Simple Send Mail Function in CodeIgniter

Make this function in your Model.

function send_mail($to,$firstname,$Mobile,$Country)
    {
            $subject = 'Save 3 Lives';
            $headers = "From: " . $_SERVER['HTTP_HOST'] . "\r\n";
            $headers .= "Reply-To: noreply@" . $_SERVER['HTTP_HOST'] . "\r\n";
            $headers .= "CC: noreply@" . $_SERVER['HTTP_HOST'] . "\r\n";
            $headers .= "MIME-Version: 1.0\r\n";
            $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
           
            $message = '<html><body>';
            $message .= '<h2 style="align:center">Thank You </h2>';'<br>';
            $message .= '<h2 style="align:center">Thank You </h2>';'<br>';
            $message .= '<table align="left" style="border-color: #000; margin: 16 pxauto; " cellpadding= " 10 ">';
            $message .= "<tr style='background: #437C17; color:#fff;'><td><strong>Dear:</strong> </td><td>" . $firstname . "</td></tr>";
            $message .= "<tr><td><strong>Email:</strong> </td><td>" . $to . "</td></tr>";
            $message .= "<tr><td><strong>Phone:</strong> </td><td>" . $Mobile . "</td></tr>";
            $message .= "<tr><td><strong>Country:</strong> </td><td>" . $Country . "</td></tr>";
            $message .= "</table>";
            $message .= "</body></html>";

         if(mail($to, $subject, $message, $headers))
            {
                return TRUE;
            }
        }


 Now put this code into your insert function at the end in Model to fetch data which you want to send.
 
       {  
             $this->send_mail($Email, $firstname, $Mobile, $Country);
        }





0 comments:

Post a Comment