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.