0

HTML Code:

    <html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>BuddyTeam | Website</title>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

    <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
    <div id="page-wrap">
        <img src="images/title.png" alt="BuddyTeam | Website" /><br /><br />

        <div id="contact-area">

            <form method="post" action="contactengine.php">
                <p style="text-align:right" onclick="alert('Só podes registar uma conta secundária se tiveres uma principal!        Neste espaço escreve o Nickname da tua conta registada no Servidor.')"><font color="blue">Precisas de ajuda? Clica Aqui!</font></p>
                <label for="Nickname"></label>
                <p><font face="serif"></font></p><input type="text" name="Nickname" id="Nickname" placeholder="Informa o Nickname da conta principal registada no Servidor." required />
                <p style="text-align:right" onclick="alert('Para não haver fraudes precisamos de saber que és mesmo tu!                   Vai ao Servidor com a tua conta registada, usa o comando ( /meuid ) e escreve os números neste espaço.')"><font color="blue">Precisas de ajuda? Clica Aqui!</font></p>

                <label for="ID"></label>
                <p><font face="serif"></font></p><input type="text" name="ID" id="ID" placeholder="Informa o ID da conta principal registada no Servidor." required />
                <p style="text-align:right" onclick="alert('Contas nunca são demais!                                                                        Neste espaço escreve o Nickname da nova conta que queres registar.')"><font color="blue">Precisas de ajuda? Clica Aqui!</font></p>

                <label for="Novo"></label>
                <input type="text" name="Novo" id="Novo" placeholder="Informa o Nickname da conta que pretendes registar." required />
                <p style="text-align:right" onclick="alert('Segurança em primeiro lugar!                                                                  Neste espaço escreve uma senha para a nova conta que queres registar.')"><font color="blue">Precisas de ajuda? Clica Aqui!</font></p> 

                <label for="Senha"></label>
                <input type="text" name="Senha" id="Senha" placeholder="Informa uma senha para a tua nova conta." required />   
                <p style="text-align:right" onclick="alert('Depois entra em contacto!                                                                      Coloca aqui o teu Email para seres contacto quando a conta for registada.')"><font color="blue">Precisas de ajuda? Clica Aqui!</font></p>    

                <label for="Email"></label>
                <input type="text" name="Email" id="Email" placeholder="Informa um Email para contacto.">

                <input type="submit" name="submit" value="Enviar" class="submit-button" />
            </form>

            <div style="clear: both;"></div>

        </div>

    </div>
</body>
</html>

PHP Code:

    <?php

$EmailFrom = "geral@buddyplays.net";
$EmailTo = "geral@buddyplays.net";
$Subject = "Novo Pedido de Registo de Conta";
$Nickname = Trim(stripslashes($_POST['Nickname']));
$ID = Trim(stripslashes($_POST['ID'])); 
$Novo = Trim(stripslashes($_POST['Novo'])); 
$Senha = Trim(stripslashes($_POST['Senha'])); 
$Email = Trim(stripslashes($_POST['Email'])); 

// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=erro.html\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Conta Registada: ";
$Body .= $Nickname;
$Body .= "\n";
$Body .= "ID da Conta Registada: ";
$Body .= $ID;
$Body .= "\n";
$Body .= "Nova Conta: ";
$Body .= $Novo;
$Body .= "\n";
$Body .= "Senha: ";
$Body .= $Senha;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=concluido.php\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=erro.html\">";
}
?>

When I fill out the form and submit, I'm redirected to "erro.html" and the email is not sent. What is wrong?

The system stops working from one moment to another without me doing any kind of editing.

What do I need to change for the system to work again?

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
  • The PHP is your whole code or a minimal version? Is redirect thrown from `if ($success){` or `if (!$validationOK) {`? (Also why redirect with HTML/meta, just use `header`) – chris85 Nov 14 '17 at 23:00
  • what is location of `contactengine.php` ? – helpdoc Nov 14 '17 at 23:06

1 Answers1

0

The problem is that your mail() function isn't working because you have supplied an invalid fourth parameter (as your From address). "From: <$EmailFrom>" shouldn't have the brackets around the email address. If you do make use of the brackets, you need to supply a name in front of them.

Instead of $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

What you're looking to do is add it as a header:

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'From: ' . $Nickname. ' <' . $EmailFrom . '>';
$success = mail($EmailTo, $Subject, $Body, $headers);`

This will evaluate to: From: $Nickname <$EmailFrom>.

Also note that some mail servers prevent the From address from being manipulated in order to prevent phishing.

You're getting a 404 simply because erro.html doesn't exist on your server. Creating the relevant file will resolve the error and redirect you there automatically when there's an error sending of the email.

Hope this helps! :)

Obsidian Age
  • 41,205
  • 10
  • 48
  • 71