PHP - You can't use this API [closed] - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Sunday, September 4, 2022

PHP - You can't use this API [closed]

I'm setting a server-side email sender with PHP.
This PHP have HTTP_REFERER So only I can access it.
However, when I'm trying to access it I'm getting my error message You can't use this API!
Even with localhost:3000, It's not working.\

What I have tried

I have tried to copy the URL from google, still not works.
My URL looks like this: https://website.org/contact.

index.php

<?php

header("Access-Control-Allow-Origin: *");

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

// Get Referer server
if ($_SEVER['HTTP_REFERER'] === "https://mywebsite.org/") {
    // Get data from GET Method
    $first = isset($_GET['first']) ? $_GET['first'] : null;
    $last = isset($_GET['last']) ? $_GET['last'] : null;
    $email = isset($_GET['email']) ? $_GET['email'] : null;
    $message = isset($_GET['message']) ? $_GET['message'] : null;

    if ($first && $last && $email && $message) {
        require 'vendor/autoload.php';

        $mail = new PHPMailer(true);

        try {
            //Server settings
            $mail->isSMTP();                                            //Send using SMTP
            $mail->Host       = 'host';                     //Set the SMTP server to send through
            $mail->SMTPAuth   = true;                                   //Enable SMTP authentication
            $mail->Username   = 'username';                     //SMTP username
            $mail->Password   = 'pass';                               //SMTP password
            $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            //Enable implicit TLS encryption
            $mail->Port       = 465;                                    //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`

            //Recipients
            $mail->setFrom('email', 'Mailer');
            $mail->addAddress('email');
            $mail->addReplyTo('email', 'Office');

            //Content
            $mail->isHTML(true);                                  //Set email format to HTML
            $mail->Subject = 'Customer Support Message';
            $mail->Body    = `Content`;

            $mail->send();
            echo 'Message has been sent';
        } catch (Exception $e) {
            echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
        }
    } else {
        echo "All Field are required!";
    }
} else {
    echo "You can't use this API!";
}

I'm new to PHP so maybe its a stupid mistake.



source https://stackoverflow.com/questions/73594507/php-you-cant-use-this-api

No comments:

Post a Comment