codeigniter查询错误

时间:2015-09-21 11:07:49

标签: codeigniter email

我正在编写此代码以从以下查询中收到电子邮件,但它给了我一个错误:

  

未定义的变量电子邮件

看起来该查询生成的结果无法在foreach循环之外看到,但我想要该电子邮件变量。错误发生在send_session_close_mail()函数:

 $qry="select email from end_employee_master where 
         id=(select eemp_id from book_e_counseling_mst where CaseId='EC-".$cid."')" ; 

$query=$this->db->query($qry);
$num=$query->num_rows(); 
foreach($query->result() as $row) { 
     $email=$row->email; 
} 

完整代码列表:

<?php

    class Email_model extends CI_Model {

    private $config = null;

    public function __construct() {
        parent::__construct();
        $this->load->helper(array('form', 'url'));
      $this->load->library('email');
        $this->config = Array(
            'protocol' => 'smtp',
            'smtp_host' => 'mail.santulan.co.in',
            'smtp_port' => 25,
            'smtp_user' => 'no.reply@santulan.co.in', // change it to yours
            'smtp_pass' => 'Admin@123', // change it to yours
            'mailtype' => 'html',
            'charset' => 'iso-8859-1',
            'wordwrap' => TRUE
        );
        $this->email->initialize($this->config);
    }

    public function send_password_reset_mail($new_pass, $email) {
        $base_url = base_url();
        $this->email->initialize($this->config);
        $message_str = '<p><span style="font-family: \'Tahoma\', Tahoma; font-weight:normal;">Hello there,</span></p>
                        <p><span style="font-family: \'Tahoma\',Tahoma; font-weight:normal;">You have requested to reset your password. Please click on the below link. </span></p>
                        <p><span style="font-family: \'Tahoma\', Tahoma; font-weight:normal;"><a href="' . $base_url . 'index.php/login/reset_password?id=' . $new_pass . '" target="_blank">Click here</a></span></p>
                        <p><span style="font-family: \'Tahoma\', Tahoma; font-weight:normal;">Please do not share this link with anyone else.</span></p>
                        <p>&nbsp;</p>
                        <p><span style="font-weight:normal; font-family: \'Tahoma\', Tahoma;">Sincerely,</span></p>
                        <p><span style="font-weight:normal; font-family: \'Tahoma\', Tahoma;">Team Santulan&nbsp;</span></p>
                        <p><br />
                                </p>';
        $this->email->from('no.reply@santulan.co.in', 'Santulan Suport Team');
        $this->email->to($email);
        $this->email->subject('Message From Santulan: Password Reset Link');
        $this->email->message($message_str);
        $this->email->send();
    }

    /**

    function to change the password of the team
    **/
     public function send_password_reset_mail_team($new_pass, $email) {
        $base_url = base_url();
        $this->email->initialize($this->config);
        $message_str = '<p><span style="font-family: \'Tahoma\', Tahoma; font-weight:normal;">Hello there,</span></p>
                        <p><span style="font-family: \'Tahoma\',Tahoma; font-weight:normal;">You have requested to reset your password. Please click on the below link. </span></p>
                        <p><span style="font-family: \'Tahoma\', Tahoma; font-weight:normal;"><a href="' . $base_url . 'index.php/login/reset_password_team?id=' . $new_pass . '" target="_blank">Click here</a></span></p>
                        <p><span style="font-family: \'Tahoma\', Tahoma; font-weight:normal;">Please do not share this link with anyone else.</span></p>
                        <p>&nbsp;</p>
                        <p><span style="font-weight:normal; font-family: \'Tahoma\', Tahoma;">Sincerely,</span></p>
                        <p><span style="font-weight:normal; font-family: \'Tahoma\', Tahoma;">Team Santulan&nbsp;</span></p>
                        <p><br />
                                </p>';
        $this->email->from('no.reply@santulan.co.in', 'Santulan Suport Team');
        $this->email->to($email);
        $this->email->subject('Message From Santulan: Password Reset Link');
        $this->email->message($message_str);
        $this->email->send();
    }

    /**
     * Send mail to Counselor that Conversation has been
     * updated by User for the E-Counseling case.
     * @param type $data About case ID description etc.
     */
    public function set_EC_notify_mail_counselor($data) {
        $this->load->model('users');
        $userdata = $this->users->get_end_employee_Detail($data['eemp_id']);
        $counselordata = $this->users->get_counselor_Detail($data['counseler_id']);
        if ($userdata && $counselordata) {
            $mailSubject = "E-Counseling Conversation Reply for Case ID " . $data['CaseId'] . ".";
            $mailBody = '<p>Hi ' . $counselordata->name . ',</p>
                    <p>Greeting for the day.</p>
                    <p>You have new reply for the E-Counseling Case ID ' . $data['CaseId'] .
                    ' feedback conversation. This reply is from employee ' . $userdata->name . ' ' .
                    $userdata->lname .
                    '. Please login to <a href="http://www.santulan.co.in" target="_blank" title="http://www.santulan.co.in" name="http://www.santulan.co.in">http://www.santulan.co.in</a> to respond this.</p>
                    <p>&nbsp;</p>
                    <p><span style="font-weight:normal;">Thanks &amp; Regards,</span></p>
                    <p><span style="font-weight: normal;">Santulan Support Team</span></p>';
            $this->email->initialize($this->config);
            $this->email->from('no.reply@santulan.co.in', 'Santulan Suport Team');
            $this->email->to($counselordata->email);
            $this->email->subject($mailSubject);
            $this->email->message($mailBody);
            $this->email->send();
        }
    }

    /**
     * Send mail to Counselor that Conversation has been
     * updated by User for the E-Counseling case.
     * @param type $data About case ID description etc.
     */
    public function set_EC_notify_mail_endUser($data) {
        $this->load->model('users');
        $userdata = $this->users->get_end_employee_Detail($data['eemp_id']);
        $counselordata = $this->users->get_counselor_Detail($data['counseler_id']);
        if ($userdata && $counselordata) {
            $mailSubject = "E-Counseling Conversation Reply for Case ID " . $data['CaseId'] . ".";
            $mailBody = '<p>Hi ' . $userdata->name . ' ' .
                    $userdata->lname . ',</p>
                    <p>Greeting for the day.</p>
                    <p>You have new reply for the E-Counseling Case ID ' . $data['CaseId'] .
                    ' feedback conversation. This reply is from Counselor ' . $counselordata->name .
                    '. Please login to <a href="http://www.santulan.co.in" target="_blank" title="http://www.santulan.co.in" name="http://www.santulan.co.in">http://www.santulan.co.in</a> to respond this.</p>
                    <p>&nbsp;</p>
                    <p><span style="font-weight:normal;">Thanks &amp; Regards,</span></p>
                    <p><span style="font-weight: normal;">Santulan Support Team</span></p>';
            $this->email->initialize($this->config);
            $this->email->from('no.reply@santulan.co.in', 'Santulan Suport Team');
            $this->email->to($counselordata->email);
            $this->email->subject($mailSubject);
            $this->email->message($mailBody);
            $this->email->send();
        }
    }

    public function send_feedback_mail($case_id, $emailID, $fname, $lname) {
        $base_url = base_url();
        $this->email->initialize($this->config);
        $message_str = '<pre><em><strong>hello $fname end user why you want feedback from me cant you call me or you dont hav'
                . ' enough balance in your phone. clik on the link below http://www.santulan/feedback/feedback_form?case_id=EC-12&emp_id=2&c_id</strong></em></pre>';
        $this->email->from('no.reply@santulan.co.in', 'Santulan Suport Team');
        $this->email->to($emailID);
        $this->email->subject('Santulan-Feedback Email');
        $this->email->message('$message_str');
        $email->send();
    }

    /**public function send_session_details($output) {
        $base_url = base_url();
        $this->email->initialize($this->config);
        $case_id = $output['CaseId'];
        $sessionDetail = $output['currentSessionDetails'];


        $query = " SELECT email FROM end_employee_master WHERE id=(SELECT eemp_id FROM book_e_counseling_mst WHERE CaseId='$case_id')";
        $result = $this->db->query($query);
        foreach ($result->result() as $row) {
            $mail_id = $row->email;
        }
        $message_str = '<pre><em><strong>Hello counseler you have new case</strong></em></pre>';
        $this->email->from('no.reply@santulan.co.in', 'Santulan Team');
        $this->email->to($mail_id);
        $this->email->subject('Counselor you have new case come on');
        $this->email->message($message_str);
        $this->email->send();
    }**/

    public function send_helpline_registration_mail($gvfcode,$data,$password) {
        $base_url = base_url();
        $this->email->initialize($this->config);
        $email = $data['email'];
        $firstname = $data['name'];
        $lastname = $data['lname'];
        $pass = $password;
        $url = 'http://www.santulan.co.in/registration/verification/' . $gvfcode;
        $message = "Dear $firstname $lastname, \n " .
        '<p dir="ltr" style="color: rgb(34, 34, 34); font-family:Tahoma, Tahoma; font-size: 14 background-color: rgb(255, 255, 255);">
            Thank you for reaching out to SANTULAN. Please activate your account by clicking on the below link.</p>
        <p dir="ltr" style="color: rgb(34, 34, 34); font-family: Tahoma, Tahoma;  background-color: rgb(255, 255, 255);">
            <!---<strong>You can take counselling via phone or face 2 face</strong></p>--->
        <p dir="ltr" style="color: rgb(34, 34, 34); font-family: Tahoma, Tahoma; background-color: rgb(255, 255, 255);">
        <!---<strong>For more details contact or Helpline no.</p>--->
        <p dir="ltr" style="color: rgb(34, 34, 34); font-family: Tahoma, Tahoma; background-color: rgb(255, 255, 255);">
            <!---<strong>Also you can activate your account by clicking below link</p>--->
                <p dir="ltr" style="color: rgb(34, 34, 34); font-family: Tahoma, Tahoma; fon background-color: rgb(255, 255, 255);">
            <a href="' . $url .'"><b>' . $url .'</b></a></p>
        <p dir="ltr" style="color: rgb(34, 34, 34); font-family: Tahoma, Tahoma;  background-color: rgb(255, 255, 255);">
            Your login id is your email address :  ' . $email . '</p>
        <p dir="ltr" style="color: rgb(34, 34, 34); font-family: Tahoma, Tahoma; background-color: rgb(255, 255, 255);">

Your password is : 
 ' . $pass . '</p>
        <p dir="ltr" style="color: rgb(34, 34, 34); font-family: Tahoma, Tahoma; background-color: rgb(255, 255, 255);">
            <em>Thank you,<br />
            Team&nbsp;Santulan&nbsp;</em></p>';
        $this->email->from('no.reply@santulan.co.in', 'Santulan Suport Team');
        $this->email->to(trim($email));
        $this->email->subject('Registration Confirmation');
        $this->email->message($message);
        $this->email->send();
    }


    /**
    Function to send email form submitted mail for E-counseling 
    **/

     public function send_mail_to_user($email)
        {
                $base_url = base_url();
        $this->email->initialize($this->config);
        $message_str = '<p> Hello There'.
                        '<br>'.
                '<br>We have received your request. We will be in touch shortly'.
                '<br>'.
                '<br>Team Santulan
                                </p>';
        $this->email->from('no.reply@santulan.co.in', 'Santulan Suport Team');
        $this->email->to($email);
        $this->email->subject('Message From Santulan: You filled a form for E-Counseling');
        $this->email->message($message_str);
        $this->email->send();

    }


    /**
    Function to send email form submitted mail for Telephonic-counseling 
    **/

     public function send_mail_to_tele_user($email)
        {
                $base_url = base_url();
        $this->email->initialize($this->config);
        $message_str = '<p> Hello There'.
                        '<br>'.
                '<br>We have received your request. We will be in touch shortly'.
                '<br>'.
                '<br>Team Santulan
                                </p>';
        $this->email->from('no.reply@santulan.co.in', 'Santulan Suport Team');
        $this->email->to($email);
        $this->email->subject('Message From Santulan: Your Counseling Appointment');
        $this->email->message($message_str);
        $this->email->send();

    }


       /**
    Function to send email form submitted mail for F to F-counseling 
    **/

     public function send_mail_to_ftof_user($email)
        {
                $base_url = base_url();
        $this->email->initialize($this->config);
        $message_str = '<p> Hello There'.
                '<br>We have received your request. We will be in touch shortly'.
                '<br>'.
                '<br>Team Santulan
                                </p>';
        $this->email->from('no.reply@santulan.co.in', 'Santulan Suport Team');
        $this->email->to($email);
        $this->email->subject('Message From Santulan: Your Counseling Appointment');
        $this->email->message($message_str);
        $this->email->send();

    }




       /**
    Function to send email form submitted mail for video - counseling 
    **/

     public function send_mail_to_video_user($email)
        {
                $base_url = base_url();
        $this->email->initialize($this->config);
        $message_str ='<p> Hello There'.
                   '<br>'.
                '<br>We have received your request. We will be in touch shortly'.
                '<br>'.
                '<br>Team Santulan
                                </p>';
        $this->email->from('no.reply@santulan.co.in', 'Santulan Suport Team');
        $this->email->to($email);
        $this->email->subject('Message From Santulan: Your Counseling Appointment');
        $this->email->message($message_str);
        $this->email->send();

    }

    /**
       public function send_mail_fs()
    {

        $userid = $this->session->all_userdata();
        $email = $userid['logged_in']['email'];
                 $base_url = base_url();
        $this->email->initialize($this->config);
        $message_str = '<p>Hello There,<br>
        You have new case for assignment,please login and assighn it to counselor.
                                </p>';
        $this->email->from('no.reply@santulan.co.in', 'Santulan Suport Team');
        $this->email->to($email);
        $this->email->subject("This is first support mail");
        $this->email->message($message_str);
        $this->email->send();
    }

    **/

    public function send_counselor_mail($email)
    {
       $this->email->initialize($this->config);
        $message_str = 'Hello this is mail for counselor testing';
        $this->email->from('no.reply@santulan.co.in', 'Santulan Suport Team');
        $this->email->to("hemantrandivehr@gmail.com");
        $this->email->subject("This is first support mail");
        $this->email->message($message_str);
        $this->email->send();
    }


    /**

    Function to send mail to enduser thatb session is closed 
    **/
 public function send_session_close_mail($session_id,$c_type,$cid)
    {
            //$url = 'https://www.surveymonkey.com/r/?sm=s8ma655VB3Jd39QMaNl2YPaVWsbL3XPHrBW6ryEbhkGruBuQ8SLyNsX3hY6gwgopkuIJdbQy0GrI%2fPd77ydWOSP4R%2fOxaHLr52uARCuMiLg%3d';
        if($c_type=='E_Counseling')
        {
           $qry="select email from end_employee_master where id=(select eemp_id from book_e_counseling_mst where CaseId='EC-".$cid."')"  ;
           $query=$this->db->query($qry);
           $num=$query->num_rows();


           foreach($query->result() as $row)
            {

               $email=$row->email;
            }

         $this->email->initialize($this->config);
        $message_str = 'Your session for '.$c_type.'is closed,your case id is '.$cid.' please click on the link <a href="https://www.surveymonkey.com/r/NNLK2R2">Click Here</a> ';
        $this->email->from('no.reply@santulan.co.in', 'Santulan Suport Team');
        $this->email->to($email);
        $this->email->subject("This is mail from counselor");
        $this->email->message($message_str);
        $this->email->send();
        }
      if($c_type=='Telephone_Counseling')
        {
            $qry="SELECT email FROM book_tele_counseling_mstr WHERE CaseId like 'TC-" .  $cid . "'";
    $query=$this->db->query($qry);
    $num=$query->num_rows();


           foreach($query->result() as $row)
            {
               //$eemp_id=$row->eemp_id;
               $email=$row->email;
            }

         $this->email->initialize($this->config);
    $message_str = 'Your session for'.$c_type.'is closed,your case id is '.$cid.' please click on the link <a href="https://www.surveymonkey.com/r/NNLK2R2">Click Here</a> ';
        $this->email->from('no.reply@santulan.co.in', 'Santulan Suport Team');
        $this->email->to($email);
        $this->email->subject("This is mail from counselor");
        $this->email->message($message_str);
        $this->email->send();


          }
    if($c_type=='F2F_Counseling')
        {
                    $qry="SELECT email FROM  book_ff_counseling_mstr WHERE CaseId like 'FC-" .  $cid . "'";
    $query=$this->db->query($qry);
    $num=$query->num_rows();




           foreach($query->result() as $row)
            {
               //$eemp_id=$row->eemp_id;
               $email=$row->email;
            }

         $this->email->initialize($this->config);
          $message_str = 'Your session for'.$c_type.'is closed,your case id is '.$cid.' please click on the link <a href="https://www.surveymonkey.com/r/NNLK2R2">Click Here</a> ';
        $this->email->from('no.reply@santulan.co.in', 'Santulan Suport Team');
        $this->email->to($email);
        $this->email->subject("This is mail from counselor");
        $this->email->message($message_str);
        $this->email->send();
        }
        if($c_type=='Video_Counseling')
        {

            $qry="SELECT email FROM  book_vedio_counseling_mstr WHERE CaseId like 'VC-" .  $cid . "'";
            $query=$this->db->query($qry);
            $num=$query->num_rows();


           foreach($query->result() as $row)
            {
               //$eemp_id=$row->eemp_id;
               $email=$row->email;
            }

         $this->email->initialize($this->config);
             $message_str = 'Your session for'.$c_type.'is closed,your case id is '.$cid.' please click on the link <a href="https://www.surveymonkey.com/r/NNLK2R2">Click Here</a> ';
        $this->email->from('no.reply@santulan.co.in', 'Santulan Suport Team');
        $this->email->to($email);
        $this->email->subject("This is mail from counselor");
        $this->email->message($message_str);
        $this->email->send();
        }


    }

}

1 个答案:

答案 0 :(得分:0)

根据您的评论339和340行号显示错误,其中的电子邮件变量位于send_session_close_mail() 接下来是您的代码:

       foreach($query->result() as $row)
            {

               $email=$row->email;
            }

         $this->email->initialize($this->config);
        $message_str = 'Your session for '.$c_type.'is closed,your case id is '.$cid.' please click on the link <a href="https://www.surveymonkey.com/r/NNLK2R2">Click Here</a> ';
        $this->email->from('no.reply@santulan.co.in', 'Santulan Suport Team');
        $this->email->to($email);
        $this->email->subject("This is mail from counselor");
        $this->email->message($message_str);
        $this->email->send();

我知道您要在foreach循环播放时向多个电子邮件ID发送电子邮件。并且声明了loop变量电子邮件。

我建议您将所有发送电子邮件代码放在loop中,如下所示,然后尝试一次

    foreach($query->result() as $row)
    {

               $email=$row->email;


         $this->email->initialize($this->config);
        $message_str = 'Your session for '.$c_type.'is closed,your case id is '.$cid.' please click on the link <a href="https://www.surveymonkey.com/r/NNLK2R2">Click Here</a> ';
        $this->email->from('no.reply@santulan.co.in', 'Santulan Suport Team');
        $this->email->to($email);
        $this->email->subject("This is mail from counselor");
        $this->email->message($message_str);
        $this->email->send();
   }

这可以解决您的问题。