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
}