0

I'm having a problem when submitting email through loop. I'm getting different username in html and plain text format.

This is my controller function report() {

    $this->load->model('Searchmonitoring_db');
    $results = $this->Searchmonitoring_db->getLogs();

    if (!$results)
            return false;

    $this->load->library('email');
    $config['mailtype'] = 'html';
    $this->email->initialize($config);

    foreach ($results as $result) {

        $fname = $result['fname'];
        $username = $result['username'];
        $subject_keyword = $result['grpname'];

        if ($subject_keyword == "") {

            $findfields['clientid'] = $result['clientid'];
            $findfields['grouping'] = $result['grouping'];
            $keywords = $this->Searchmonitoring_db->getKeywords($findfields);

            if ($keywords['db']) {
                foreach ($keywords['db'] as $kw) {
                    if ($subject_keyword != "")
                            $subject_keyword .= ", ";
                    $subject_keyword .= $kw['query'];
                }
            }
        }

        $this->email->clear(TRUE);

        $managerEmail = $result['manager_email'];
        $manager = $result['manager'];
        $salespersonEmail = $result['salesperson_email'];
        $salesperson = $result['salesperson'];
        $clientEmail = $result['email'];

        if($managerEmail) {
            $this->email->from($managerEmail, $manager);
        } elseif($salespersonEmail) {
            $this->email->from($salespersonEmail, $salesperson);
        }

        $this->email->to($clientEmail);


        $arrfname = explode("/", $fname);
        $subject = "Your $subject_keyword monitoring report";
        $this->email->subject($subject);
        $message = $this->load->view('emailtemplate', $result, true);
        $this->email->message($message);
        $this->email->attach("../export/$username/" . end($arrfname) . ".zip");

        if ($this->email->send()) {
            $update['id'] = $result['logid'];
            $searchlog['result'] = 'Sent';
            $this->Searchmonitoring_db->updateLog($update, $searchlog);
        }
    }
}

This is my email template

<html>
<body>

<p>Hi <?php echo $firstname; ?></p>
<p>Thanks for your business!</p>
<p>
<?php
if($manager) {
    echo nl2br($manager_email_signature);
} elseif($salesperson) {
    echo nl2br($salesperson_email_signature);
} ?>
</p>
</body>
</html>

I also use postmark to monitor my emails and when I clicked the email the html format get the correct name but when I clicked the plain text format it has the incorrect name.

example: html: says "Hi jack thanks for your business". plain text: says "Hi anderson thanks for your business".

I noticed that plain text gets the name of the first email in loop

codeninja
  • 68
  • 1
  • 8

1 Answers1

0

Try use:

  $this->email->set_alt_message('This is the alternative message');
Artur
  • 101
  • 2