ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    HTML Form filling Integrating through GCP Serverless

    IT Discussion
    2
    4
    345
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L
      Laksh1999
      last edited by

      Hi All,

      I have created a new IT portal for my organization. I have created a form in there to submit their Name,Email,Subject,Message. I am in need to have the user information who have submitted the form from their end.Once they submit that form that needs to send an email to IT helpdesk email id. That will get converted into ticket.Got help from Chat GPT but not all the time the Chat GPT can help like Humans in this forum like this.

      I need to know why this error is coming

      Error Logs for Reference

      2023/04/11 06:52:28 [error] 19#19: *5 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught LogicException: Your function must have "Psr\Http\Message\ServerRequestInterface" as the typehint for the first argument in /workspace/vendor/google/cloud-functions-framework/src/FunctionWrapper.php:99 Stack trace: #0 /workspace/vendor/google/cloud-functions-framework/src/FunctionWrapper.php(82): Google\CloudFunctions\FunctionWrapper->throwInvalidFunctionException() #1 /workspace/vendor/google/cloud-functions-framework/src/FunctionWrapper.php(36): Google\CloudFunctions\FunctionWrapper->validateFunctionSignature(Object(ReflectionFunction)) #2 /workspace/vendor/google/cloud-functions-framework/src/Invoker.php(53): Google\CloudFunctions\FunctionWrapper->__construct('submitForm') #3 /workspace/vendor/google/cloud-functions-framework/router.php(56): Google\CloudFunctions\Invoker->__construct('submitForm', 'http') #4 /workspace/vendor/google/cloud-functions-framework/router.php(59): {closure}() #5 {main} thrown in /workspace/vendor/google/cloud-functions-framework/src/F" while reading response header from upstream, 
      

      index.php

      <?php
      require __DIR__ . '/vendor/autoload.php';
      
      use PHPMailer\PHPMailer\PHPMailer;
      use Psr\Http\Message\ServerRequestInterface;
      
      function submitForm(ServerRequestInterface $request) {
        $parsedBody = $request->getParsedBody();
      
        $name = $parsedBody['name'];
        $email = $parsedBody['email'];
        $subject = $parsedBody['subject'];
        $message = $parsedBody['message'];
      
        // Write the form data to logs
        $log_message = "Form submission: Name=$name, Email=$email, Subject=$subject, Message=$message";
        error_log($log_message);
      
        // Send an email to the helpdesk only if email is from @domain.com domain
        if (strpos($email, '@domain.com') !== false) {
          $mail = new PHPMailer(true);
          $mail->isSMTP();
          $mail->SMTPAuth = true;
          $mail->Host = 'smtp.gmail.com';
          $mail->Port = port number;
          $mail->Username = 'email';
          $mail->Password = 'password';
          $mail->setFrom($email);
          $mail->addAddress('helpdesk Email');
          $mail->Subject = $subject;
          $mail->Body = $message;
          $mail->send();
        }
      
        $message = 'Form submission successful!'; // Include a success message in the response
        return $message;
      }
      
      

      composer.json

      {
        "require": {
          "phpmailer/phpmailer": "^6.5"
        },
        "autoload": {
          "psr-4": {
            "": "src/"
          }
        },
        "scripts": {
          "start": "php -S localhost:8080 -t public/",
          "serve": "functions-framework --target=submitForm --signature-type=http"
        },
        "minimum-stability": "dev",
        "prefer-stable": true
      }
      
      1 1 Reply Last reply Reply Quote 1
      • 1
        1337 @Laksh1999
        last edited by 1337

        @Laksh1999

        Why are you using email for this?

        This problem has already been solved in a number of better ways and basically all helpdesk systems have this:

        • HTML code or web forms you can paste into your site that will allow you to create a ticket from your web site.
        • Support portal where the users can see their tickets, write new ones and reply to tickets.
        • API integration that allows you to submit tickets directly from other places, like a website.

        Pick one of those ways instead and you'll have a much better, cleaner and more reliable solution.

        L 1 Reply Last reply Reply Quote 1
        • L
          Laksh1999 @1337
          last edited by

          @Pete-S said in HTML Form filling Integrating through GCP Serverless:

          API integration that allows you to submit tickets directly from other places, like a website.

          How to create an api to send the email to the helpdesk email from the google form?
          Here the user send an email to helpdesk email to create a ticket for their daily issue

          1 1 Reply Last reply Reply Quote 0
          • 1
            1337 @Laksh1999
            last edited by

            @Laksh1999 said in HTML Form filling Integrating through GCP Serverless:

            @Pete-S said in HTML Form filling Integrating through GCP Serverless:

            API integration that allows you to submit tickets directly from other places, like a website.

            How to create an api to send the email to the helpdesk email from the google form?
            Here the user send an email to helpdesk email to create a ticket for their daily issue

            API is the last resort and only needed in special cases.

            And you don't need google forms at all.

            Helpdesks like zendesk, freshdesk, zoho desk etc have widgets. It's some html/javascript you insert into your web site and a customizable form will appear.

            When the user submits the form a ticket will be created with all the right information in the proper fields.

            Search for the name of your helpdesk and widget and you'll find it.

            1 Reply Last reply Reply Quote 1
            • 1 / 1
            • First post
              Last post