• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
View ignores 2 variables when sending as html-email

#1
[eluser]ingrimm[/eluser]
Hey guys.

I'm having a strange problem here.

I use CI to either build me an html email with some data of a previously filled form.
I have 2 Buttons, one lets me preview the email and the other sends the data to my email adress. The codebase are almost 500 lines.

There are two variables wich are shown correcly in the preview but remain empty when i send the email this is the controller:

Code:
<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Emailtemplate extends CI_Controller {

    public $templateData;

    public function index() {
        $this->load->helper(array('form', 'url'));
    }

    function getTrafficIndex($alltweets, $index1of90) {
        $trafficIndex = 0;
        $trafficIndex = $alltweets/$index1of90;
        return number_format($trafficIndex, 2, '.', '');
    }

    function findInfuentialTweet($data) {
        return $tweet;
    }

    function findBasicTopics($data) {
        return $basicArray;
    }

    function getReachIndex($allreach, $index2of90) {
        $reachIndex = 0;
        $reachIndex = $allreach / $index2of90;
        return number_format($reachIndex, 2, '.', '');
    }

    function getindexpercent($alltweets, $tweets) {
        $indexpercent = 100 / $alltweets * $tweets;
        return $indexpercent;
    }

    function getreachpercent($allreach, $reach) {
        $reachpercent = 100 / $allreach * $reach;
        return $reachpercent;
    }

    function getTonality($value) {
        $result = "";
        if ($value > 0 && $value < 0.7) {
            $result = "low";
        } else if ($value >= 0.7 && $value < 1.3) {
            $result = "avg";
        } else if ($value >= 1.3 && $value < 2) {
            $result = "high";
        } else {
            $result = "very high";
        }
        return $result;
    }
    
    public function getpercentoftotals($value, $total) {
        $percent = "";
        $percent = 100/$total*$value;
        $percent = round($percent, 1);
        //$percent = str_replace('.',',',$percent);
        return $percent;
    }
    public function submit() {
        $tweets = $this->input->post('_tweets');
        $alltweets = $this->input->post('_alltweets');
        $allreach = $this->input->post('_allreach');
        $reach = $this->input->post('_reach');

//these are the bastards...
        $tweetavg = $this->input->post('_index1');
        $reachavg = $this->input->post('_index2');
        $tweetavg = preg_replace('/[\,]/', '', $tweetavg);
        $reachavg = preg_replace('/[\,]/', '', $reachavg);
  
        $trafficIndex = $this->getTrafficIndex($alltweets, $tweetavg);
        $reachIndex = $this->getReachIndex($allreach, $reachavg);
        $indexpercent = $this->getindexpercent($alltweets, $tweets);
        $reachpercent = $this->getreachpercent($allreach, $reach);
        $reachTonality = $this->getTonality($reachIndex);
        $tweetsTonality = $this->getTonality($trafficIndex);
        
        $topics = $this->input->post('_topics');
        $mentions = $this->input->post('_mentions');
        $preview = $this->input->post('preview');
         for($i = 0; $i < count($topics); $i++) {
           $tweetcount = $topics[$i]["tweet"]["tweet_tweetcount"];
           $tweetcount = $this->getpercentoftotals($tweetcount, $alltweets);
           $topics[$i]["tweet"]["tweet_tweetcount_perc"] = $tweetcount;
           $reachcount = $topics[$i]["tweet"]["tweet_reach"];
           $reachcount = $this->getpercentoftotals($reachcount, $allreach);
           $topics[$i]["tweet"]["tweet_reach_perc"] = $reachcount;
         }
        $data["alltweets"] = $alltweets;
        $data["allreach"] = $allreach;
        $data["reach"] = $sreach;
        $data["tweets"] = $tweets;
        $data["trafficindex"] =$trafficIndex;
        $data["reachindex"] = $reachIndex;
        $data["indexpercent"] = round($indexpercent);
        $data["reachpercent"] = round($reachpercent);
        $data["tweetstonality"] = $tweetsTonality;
        $data["reachtonality"] = $reachTonality;
    
        $data["tweetavg"] = $tweetavg;
        $data["reachavg"] = $reachavg;


        $data["topics"] = $topics;

        $data["mentions"] = $mentions;
        
        if ($preview == "true") {
            $templateData = $this->load->view('emailtemplate_view', $data);
        } else {
            $templateData = $this->load->view('emailtemplate_view', $data, TRUE);
            $date = new DateTime('NOW');
            $dateString = "FW: Twitter Mentions: ".$date->format('D').", ".$date->format('F j');
            $config['protocol'] = 'sendmail';
            $config['mailpath'] = '/usr/sbin/sendmail';
            $config['charset'] = 'utf-8';
            $config['wordwrap'] = TRUE;
            $config['mailtype'] = 'html';
            $this->load->library('email');
            $this->email->initialize($config);
            $this->email->from('some@mail.com', 'someone');
            $this->email->to('to@mail.com');
            $this->email->reply_to('noreply@some.com', 'name');
            $this->email->subject($dateString);
            $this->email->message($templateData);
            $this->email->send();
            if ( ! $this->email->send())
            {
              
                $this->email->print_debugger();// Generate error
            }
            
        }
    }

}

I know ... the code is a bit messy i stripped the comments for the lack of characters remaining for this post...
As i said: when i output the templatedata in the preview, everything works just fine. But as soon as i send the templatedata as messagebody of the email. The two variables $tweetavg and $reachavg are returning 0 when echoed in the view.

Did anyone ever have the same issue or something close to it?

Can anyone help me here?

best regards,


#2
[eluser]Aken[/eluser]
Are only those two variables being lost? What about the other input variables? It almost sounds like you're losing the POST request somewhere, but if some POST variables work and others don't, that doesn't make any sense.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.