c# http post request?

C#

            var httpClient = new HttpClient();
            var values = new Dictionary<string, string>
            {
                { "username", UsernameTextBox.Text },
                { "email", EmailTextBox.Text }
            };

            var content = new FormUrlEncodedContent(values);

            var response = await httpClient.PostAsync("http://subdomain.domain.tld/file.php", content);

            var responseString = await response.Content.ReadAsStringAsync();
            FSCMessageBox.Show(responseString);

PHP

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHP/PHPMailer/src/Exception.php';
require 'PHP/PHPMailer/src/PHPMailer.php';
require 'PHP/PHPMailer/src/SMTP.php';
$mail = new PHPMailer(true);
$whitelist = array("...");
$auth = false;
foreach($whitelist as $ip)
{
    if($ip == $_SERVER['REMOTE_ADDR']) {$auth = true;}
}
if(!$auth)
{
    http_response_code(403);
    exit();
}
try
{
    $code = "";
    for ($i = 0; $i < 8; $i++)
    {
        $ascii = rand(48, 122);
        if ($ascii > 57 && $ascii < 65 || $ascii > 90 && $ascii < 97)
        {
            $ascii -= 7;
        }
        $code .= chr($ascii);
    }
    echo $code;
    $mail->SMTPDebug = 2;                                       
    $mail->isSMTP();                                            
    $mail->Host       = "...";                    
    $mail->SMTPAuth   = true;                             
    $mail->Username   = "...";                 
    $mail->Password   = "...";                        
    $mail->SMTPSecure = "tls";                              
    $mail->Port       = 587;  
    $mail->setFrom("...", "...");           
    $mail->addAddress($_POST['email']);          
    $mail->isHtml();       
    $mail->Subject = "Verification Code";
    $mail->Body    = 
    "
    <h1>Hello, ".$_POST['username']."!</b1>
    <h4>Your verification code is ".$code.".</h4>
    <p>If you don't know why you received this E-Mail, you can safely ignore and delete it.</p>
    ";
    $mail->send();
    http_response_code(200);
}
catch (Exception $e)
{
    http_response_code(503);
    exit(); 
}
?>

Ist da ein Fehler? Wenn ich den php code ohne dem Post Request und mit festen Werten ausführe, geht alles. Also muss es doch am c# code liegen, oder?

Wenn ich es mit dem Post Request versuche, wird im Programm eine MessageBox angezeigt, wo einfach garnichts drin steht.

FSCMessageBox.Show(responseString);

Email wird auch nicht verschickt.

Die Daten wie host, username, password, email etc. sind alle richtig, da liegt der Fehler nicht.

HTML, Webseite, PHP, Webentwicklung
PHPMailer schickt unendlich E-Mails?

Ich habe eine index.php Datei auf meinem Webspace:

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require '.../PHPMailer/src/Exception.php';
require '.../PHPMailer/src/PHPMailer.php';
require '.../PHPMailer/src/SMTP.php';
$mail = new PHPMailer(true);
try
{
    $mail->SMTPDebug = 2;                                       
    $mail->isSMTP();                                            
    $mail->Host       = "...";                    
    $mail->SMTPAuth   = true;                             
    $mail->Username   = "...";                 
    $mail->Password   = "...";                        
    $mail->SMTPSecure = "tls";                              
    $mail->Port       = 587;  
    $mail->setFrom("...", "...");           
    $mail->addAddress("email1@...");
    $mail->addAddress("email2@...");      
    $mail->isHTML();                        
    $mail->Subject = "...";
    $mail->Body    = "<h1>...</h1>
    <h3>...</h3>
    <p>...</p>";
    $mail->send();
    echo "E-Mail geschickt!";
}
catch (Exception $e)
{
    echo "Konnte nicht geschickt werden! Mailer Error: {$mail->ErrorInfo}";
}
?>

Das funktioniert auch, wenn man auf die Website geht, steht da "E-Mail geschickt", und die Emails kommen auch an.

Problem: Jetzt werden jede 1-30 min Emails verschickt, bei der email1 email adresse ist alles normal, bei email2 ist der ganze Text zitiert. Wieso werden jetzt immer E-Mails verschickt? Wieso ist der Text bei email2 zitiert?

Webseite, PHP, Webentwicklung
Webseite ist nicht erreichbar?

Hey,

(Ich habe Kontakt zum Inhaber der Seite)

ich erhalte folgendes wenn ich versuche auf eine Seite zu gehen:

<?php
/*
 *	Made by Samerton
 *  https://github.com/NamelessMC/Nameless/
 *  NamelessMC version 2.0.0-pr6
 *
 *  License: MIT
 *
 *  Main index file
 */

// Uncomment to enable debugging
//define('DEBUGGING', 1);

if(defined('DEBUGGING') && DEBUGGING){
	ini_set('display_startup_errors', 1);
	ini_set('display_errors', 1);
	error_reporting(-1);
}

// Ensure PHP version >= 5.4
if(version_compare(phpversion(), '5.4', '<')){
	die('NamelessMC is not compatible with PHP versions older than 5.4');
}

// Start page load timer
$start = microtime(true);

// Definitions
define('PATH', '/');
define('ROOT_PATH', dirname(__FILE__));
$page = 'Home';

if(!ini_get('upload_tmp_dir')){
	$tmp_dir = sys_get_temp_dir();
} else {
	$tmp_dir = ini_get('upload_tmp_dir');
}

ini_set('open_basedir', ROOT_PATH . PATH_SEPARATOR  . $tmp_dir . PATH_SEPARATOR . '/proc/stat');

// Get the directory the user is trying to access
$directory = $_SERVER['REQUEST_URI'];
$directories = explode("/", $directory);
$lim = count($directories);

if(isset($_GET['route']) && $_GET['route'] == '/rewrite_test'){
    require_once('rewrite_test.php');
    die();
}

try {
	// Start initialising the page
	require(ROOT_PATH . '/core/init.php');
}
catch(Exception $e) {
	die($e->getMessage());
}

if(!isset($GLOBALS['config']['core']) && is_file(ROOT_PATH . '/install.php')) {
	Redirect::to('install.php');
}

// Get page to load from URL
if(!isset($_GET['route']) || $_GET['route'] == '/'){

	if(count($directories) > 1 && (!isset($_GET['route']) || (isset($_GET['route']) && $_GET['route'] != '/')))
		require(ROOT_PATH . '/404.php');
	else
		// Homepage
		require(ROOT_PATH . '/modules/Core/pages/index.php');

} else {
	$route = rtrim(strtok($_GET['route'], '?'), '/');

	// Check modules
	$modules = $pages->returnPages();

	// Include the page
	if(array_key_exists($route, $modules)){
	    if(!isset($modules[$route]['custom'])){
            $path = join(DIRECTORY_SEPARATOR, array(ROOT_PATH, 'modules', $modules[$route]['module'], $modules[$route]['file']));

            if(!file_exists($path)) require(ROOT_PATH . '/404.php'); else require($path);
            die();
        } else {
	        require(join(DIRECTORY_SEPARATOR, array(ROOT_PATH, 'modules', 'Core', 'pages', 'custom.php')));
	        die();
        }
	} else {
		// Use recursion to check - might have URL parameters in path
		$path_array = explode('/', $route);

		for($i = count($path_array) - 2; $i > 0; $i--){
			$new_path = '/';
			for($n = 1; $n <= $i; $n++){
				$new_path .= $path_array[$n] . '/';
			}
			$new_path = rtrim($new_path, '/');
			if(array_key_exists($new_path, $modules)){
				$path = join(DIRECTORY_SEPARATOR, array(ROOT_PATH, 'modules', $modules[$new_path]['module'], $modules[$new_path]['file']));
				if(file_exists($path)){
					require($path);
					die();
				}
			}
		}

		// 404
		require(ROOT_PATH . '/404.php');
	}

}
PC, Computer, Internet, Webseite, programmieren, Code, Error, PHP, Verbindungsprobleme

Meistgelesene Beiträge zum Thema PHP