How to upload html email template data through ajax











up vote
0
down vote

favorite












I'm trying to edit the content of an email template from database and sending it to my users. Now whenever i click on send button only half of of the html email content is sent to the user email address.



Here is my code



$this->validate($request, [
'to' => 'required|email',
'contents' => 'required',
'subject'=> 'required'
]);

$data = [
'to_user' => $request->to,
'content' => $request->contents,
'type' => 'email'
];
$unique = str_random(6) . '-'.str_random(5);

File::put("/var/www/resources/views/mails/" . $unique.".blade.php", $request->contents);

$datas = [
'from' => 'support@example.com',
'from_name' => 'Example',
'reply_to' => 'support@example.com',
'reply_to_name'=> 'Example Support Team',
'subject'=> $request->subject,
'type' => 'email',
'code' => $unique
];
AppDeliveryLog::create($data);

Mail::to($request->to)->send(new DeliveryMail($datas));


Here is the screenshot of Request being sent to controller.
Check Screenshot !



Here is the Ajax code



$('.sendEmail').on('click', function () {
email = $('#semail').val();
subject = $('#subject').val();
content = CKEDITOR.instances.CustomerEmailTemplate_content.getData();
$(".sendEmail").text("Sending... Please wait.");
$('.sendEmail').prop('disabled', true);

request = $.ajax({
url: "/ajax/send/email",
type: "post",
data: "to=" + email + "&subject=" + subject + "&contents=" + content + "&_token=" + $('meta[name="csrf-token"]').attr('content')
});

// Callback handler that will be called on success
request.done(function (response, textStatus, jqXHR) {
// Log a message to the console
if (response.result === "success") {

iziToast.success({
title: 'Success',
message: 'Email Sent Successfully.',
position: 'topRight',
timeout: '10000',
pauseOnHover: true,
});
} else {
iziToast.warning({
title: 'Success',
message: response.message,
position: 'topRight',
timeout: '10000',
pauseOnHover: true,
});
}

});

// Callback handler that will be called on failure
request.fail(function (jqXHR, textStatus, errorThrown) {
// Log the error to the console
console.error(
"The following error occurred: " +
textStatus, errorThrown
);
});

// Callback handler that will be called regardless
// if the request failed or succeeded
request.always(function () {
$(".sendEmail").text("Send Email");
$('.sendEmail').prop('disabled', false);

});

});


I'm not receiving any error but only half email is being stored.










share|improve this question


























    up vote
    0
    down vote

    favorite












    I'm trying to edit the content of an email template from database and sending it to my users. Now whenever i click on send button only half of of the html email content is sent to the user email address.



    Here is my code



    $this->validate($request, [
    'to' => 'required|email',
    'contents' => 'required',
    'subject'=> 'required'
    ]);

    $data = [
    'to_user' => $request->to,
    'content' => $request->contents,
    'type' => 'email'
    ];
    $unique = str_random(6) . '-'.str_random(5);

    File::put("/var/www/resources/views/mails/" . $unique.".blade.php", $request->contents);

    $datas = [
    'from' => 'support@example.com',
    'from_name' => 'Example',
    'reply_to' => 'support@example.com',
    'reply_to_name'=> 'Example Support Team',
    'subject'=> $request->subject,
    'type' => 'email',
    'code' => $unique
    ];
    AppDeliveryLog::create($data);

    Mail::to($request->to)->send(new DeliveryMail($datas));


    Here is the screenshot of Request being sent to controller.
    Check Screenshot !



    Here is the Ajax code



    $('.sendEmail').on('click', function () {
    email = $('#semail').val();
    subject = $('#subject').val();
    content = CKEDITOR.instances.CustomerEmailTemplate_content.getData();
    $(".sendEmail").text("Sending... Please wait.");
    $('.sendEmail').prop('disabled', true);

    request = $.ajax({
    url: "/ajax/send/email",
    type: "post",
    data: "to=" + email + "&subject=" + subject + "&contents=" + content + "&_token=" + $('meta[name="csrf-token"]').attr('content')
    });

    // Callback handler that will be called on success
    request.done(function (response, textStatus, jqXHR) {
    // Log a message to the console
    if (response.result === "success") {

    iziToast.success({
    title: 'Success',
    message: 'Email Sent Successfully.',
    position: 'topRight',
    timeout: '10000',
    pauseOnHover: true,
    });
    } else {
    iziToast.warning({
    title: 'Success',
    message: response.message,
    position: 'topRight',
    timeout: '10000',
    pauseOnHover: true,
    });
    }

    });

    // Callback handler that will be called on failure
    request.fail(function (jqXHR, textStatus, errorThrown) {
    // Log the error to the console
    console.error(
    "The following error occurred: " +
    textStatus, errorThrown
    );
    });

    // Callback handler that will be called regardless
    // if the request failed or succeeded
    request.always(function () {
    $(".sendEmail").text("Send Email");
    $('.sendEmail').prop('disabled', false);

    });

    });


    I'm not receiving any error but only half email is being stored.










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm trying to edit the content of an email template from database and sending it to my users. Now whenever i click on send button only half of of the html email content is sent to the user email address.



      Here is my code



      $this->validate($request, [
      'to' => 'required|email',
      'contents' => 'required',
      'subject'=> 'required'
      ]);

      $data = [
      'to_user' => $request->to,
      'content' => $request->contents,
      'type' => 'email'
      ];
      $unique = str_random(6) . '-'.str_random(5);

      File::put("/var/www/resources/views/mails/" . $unique.".blade.php", $request->contents);

      $datas = [
      'from' => 'support@example.com',
      'from_name' => 'Example',
      'reply_to' => 'support@example.com',
      'reply_to_name'=> 'Example Support Team',
      'subject'=> $request->subject,
      'type' => 'email',
      'code' => $unique
      ];
      AppDeliveryLog::create($data);

      Mail::to($request->to)->send(new DeliveryMail($datas));


      Here is the screenshot of Request being sent to controller.
      Check Screenshot !



      Here is the Ajax code



      $('.sendEmail').on('click', function () {
      email = $('#semail').val();
      subject = $('#subject').val();
      content = CKEDITOR.instances.CustomerEmailTemplate_content.getData();
      $(".sendEmail").text("Sending... Please wait.");
      $('.sendEmail').prop('disabled', true);

      request = $.ajax({
      url: "/ajax/send/email",
      type: "post",
      data: "to=" + email + "&subject=" + subject + "&contents=" + content + "&_token=" + $('meta[name="csrf-token"]').attr('content')
      });

      // Callback handler that will be called on success
      request.done(function (response, textStatus, jqXHR) {
      // Log a message to the console
      if (response.result === "success") {

      iziToast.success({
      title: 'Success',
      message: 'Email Sent Successfully.',
      position: 'topRight',
      timeout: '10000',
      pauseOnHover: true,
      });
      } else {
      iziToast.warning({
      title: 'Success',
      message: response.message,
      position: 'topRight',
      timeout: '10000',
      pauseOnHover: true,
      });
      }

      });

      // Callback handler that will be called on failure
      request.fail(function (jqXHR, textStatus, errorThrown) {
      // Log the error to the console
      console.error(
      "The following error occurred: " +
      textStatus, errorThrown
      );
      });

      // Callback handler that will be called regardless
      // if the request failed or succeeded
      request.always(function () {
      $(".sendEmail").text("Send Email");
      $('.sendEmail').prop('disabled', false);

      });

      });


      I'm not receiving any error but only half email is being stored.










      share|improve this question













      I'm trying to edit the content of an email template from database and sending it to my users. Now whenever i click on send button only half of of the html email content is sent to the user email address.



      Here is my code



      $this->validate($request, [
      'to' => 'required|email',
      'contents' => 'required',
      'subject'=> 'required'
      ]);

      $data = [
      'to_user' => $request->to,
      'content' => $request->contents,
      'type' => 'email'
      ];
      $unique = str_random(6) . '-'.str_random(5);

      File::put("/var/www/resources/views/mails/" . $unique.".blade.php", $request->contents);

      $datas = [
      'from' => 'support@example.com',
      'from_name' => 'Example',
      'reply_to' => 'support@example.com',
      'reply_to_name'=> 'Example Support Team',
      'subject'=> $request->subject,
      'type' => 'email',
      'code' => $unique
      ];
      AppDeliveryLog::create($data);

      Mail::to($request->to)->send(new DeliveryMail($datas));


      Here is the screenshot of Request being sent to controller.
      Check Screenshot !



      Here is the Ajax code



      $('.sendEmail').on('click', function () {
      email = $('#semail').val();
      subject = $('#subject').val();
      content = CKEDITOR.instances.CustomerEmailTemplate_content.getData();
      $(".sendEmail").text("Sending... Please wait.");
      $('.sendEmail').prop('disabled', true);

      request = $.ajax({
      url: "/ajax/send/email",
      type: "post",
      data: "to=" + email + "&subject=" + subject + "&contents=" + content + "&_token=" + $('meta[name="csrf-token"]').attr('content')
      });

      // Callback handler that will be called on success
      request.done(function (response, textStatus, jqXHR) {
      // Log a message to the console
      if (response.result === "success") {

      iziToast.success({
      title: 'Success',
      message: 'Email Sent Successfully.',
      position: 'topRight',
      timeout: '10000',
      pauseOnHover: true,
      });
      } else {
      iziToast.warning({
      title: 'Success',
      message: response.message,
      position: 'topRight',
      timeout: '10000',
      pauseOnHover: true,
      });
      }

      });

      // Callback handler that will be called on failure
      request.fail(function (jqXHR, textStatus, errorThrown) {
      // Log the error to the console
      console.error(
      "The following error occurred: " +
      textStatus, errorThrown
      );
      });

      // Callback handler that will be called regardless
      // if the request failed or succeeded
      request.always(function () {
      $(".sendEmail").text("Send Email");
      $('.sendEmail').prop('disabled', false);

      });

      });


      I'm not receiving any error but only half email is being stored.







      php html laravel email






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 5 at 19:38









      user8740586

      62




      62
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          That's because your HTML content is being interpreted as many post fields, your screenshot shows a property called subject, other contents, and then one called <html>, <head>, and so on. A possible solution is to serialize your template before sending it via HTTP request and then unserialize it.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53161080%2fhow-to-upload-html-email-template-data-through-ajax%23new-answer', 'question_page');
            }
            );

            Post as a guest
































            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote













            That's because your HTML content is being interpreted as many post fields, your screenshot shows a property called subject, other contents, and then one called <html>, <head>, and so on. A possible solution is to serialize your template before sending it via HTTP request and then unserialize it.






            share|improve this answer

























              up vote
              1
              down vote













              That's because your HTML content is being interpreted as many post fields, your screenshot shows a property called subject, other contents, and then one called <html>, <head>, and so on. A possible solution is to serialize your template before sending it via HTTP request and then unserialize it.






              share|improve this answer























                up vote
                1
                down vote










                up vote
                1
                down vote









                That's because your HTML content is being interpreted as many post fields, your screenshot shows a property called subject, other contents, and then one called <html>, <head>, and so on. A possible solution is to serialize your template before sending it via HTTP request and then unserialize it.






                share|improve this answer












                That's because your HTML content is being interpreted as many post fields, your screenshot shows a property called subject, other contents, and then one called <html>, <head>, and so on. A possible solution is to serialize your template before sending it via HTTP request and then unserialize it.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 5 at 21:16









                Max Almonte

                294




                294






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53161080%2fhow-to-upload-html-email-template-data-through-ajax%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest




















































































                    這個網誌中的熱門文章

                    Hercules Kyvelos

                    Tangent Lines Diagram Along Smooth Curve

                    Yusuf al-Mu'taman ibn Hud