Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
245 views
in Technique[技术] by (71.8m points)

Send email with codeigniter, parser library, ajax

I have a form that takes over some files and contact details and I try to send an email with Codeigniter and Parser Library.

When I use the array and the Parser library, it returns an error, without the Status variable, but the e-mail is sent properly. The email is sent well with the templates we created.

When I don't use Parse, the email is sent well and validates for me.

Can you help me? Thank You!

View ...

//...
   e.preventDefault();

      var formData = new FormData();
      for (var i = 0, len = filesToUpload.length; i < len; i++) {
        formData.append("files[]", filesToUpload[i].file);
      }
      formData.append("name", $("#name").val());
      formData.append("email", $("#email").val());
      formData.append("message", $("#message").val());
   $.ajax({
        url: "<?php echo site_url('en/get_started/send')?>",
        //dataType: 'text',
        cache: false,
        type: "POST",
        data: formData,
        contentType: false,
        processData: false,
        dataType: "JSON",
        //headers: {'Content-Type':'application/json'},
        //headers: {'Content-Type': undefined},
        success: function(data) {
          //$('.loading').slideUp();
          if (data.status) {
            $(".field").val('');
            $(".removeFile").click();
            $('.validate').slideUp();
            $('.sent-message').slideDown();
            $('.sent-message').delay(1500);
            $('.sent-message').slideUp();
          } else {

            for (var i = 0; i < data.inputerror.length; i++) {
          //    //$('[name="'+data.inputerror[i]+'"]').parent().parent().addClass('has-error');
          //    //$('[name="'+data.inputerror[i]+'"]').parent().addClass('has-error');
              $('[name="'+data.inputerror[i]+'"]').next().html(data.error_string[i]);
              $('[name="'+data.inputerror[i]+'"]').next().slideDown();
            }
          }
        },
        error: function (data) {
          //$('.loading').slideUp();
          $('.error-message').slideDown();
        }
      });
    });

Controller ...

$config['protocol']     = 'smtp';
      $config['smtp_host']    = '...';
      $config['smtp_port']    = '465';
      $config['smtp_timeout'] = '7';
      $config['smtp_user']    = '...';
      $config['smtp_pass']    = '...';
      $config['charset']      = 'UTF-8';
      $config['newline']      = "
";
      $config['mailtype']     = "html";
      //$config['wordwrap']     = TRUE;

      $from = '[email protected]';
      $to = '[email protected]';

      //$varhtml = array(
      //  'datein'  => date('d-m-Y' . ' - ' . 'H:i:s'),
      //  'name'    => $this->input->post('name'),
      //  'email'   => $this->input->post('email'),
      //  'subject' => 'Your message has been sent successfully',
      //  'message' => nl2br($this->input->post('message')),
      //);
      //Not Work!!
      //$this->load->library('parser');
      //$html = $this->parser->parse('get_started_email', $varhtml);

      $this->load->library('email');
      $this->email->initialize($config);
      //$this->email->set_header('Content-Type', 'text/html');
      $this->email->set_newline("
");
      $this->email->from($from);
      $this->email->to($to);
      $this->email->subject('andreescu.website - ' . $this->input->post('email'));
      $this->email->message('Name: ' . $this->input->post('name') . '<br>Email: ' . $this->input->post('email') . '<br>Message:<br><br>' . nl2br($this->input->post('message')));

      !! Here is the problem
      //$this->email->message($html); // 

      foreach ($filename as $value) {
        $this->email->attach($imagePath . '/' . $value);
      }

      if($this->email->send()) {
        $data['status'] = TRUE;
      } else {
        $data['status'] = FALSE;
      }

   } //End else

    echo json_encode($data);
  }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...