I can’t get a form field to be sent to the email with phpmailer

Asked

Viewed 378 times

0

I have a form that in it has a field with a (select one menu) in it there are some options where the user should choose only one and select it this form sends the information to my e-mail this feature is already working but I can not make this field appear in the email also follows my code.

    <div id="formulario">
        <form action="email.php" method="post">
            <ul>
                <li><input type="text" name="Nome" id="nome" placeholder="  Digite seu nome" required name=nome ></li>
                <li><input type="text" name="Email" placeholder="  Digite seu Email" required name=email></li>
                <li><input type="text" name="Nickname" placeholder="  Digite seu Nickname" required name=nickname></li>
                <li>
                    <select name="Games">
                        <option value ="the-elder" selected>  --- Selecione um jogo ---</option>
                        <option value ="the-elder">The Elder Scrols Online</option>
                        <option value ="archage">ArcheAge</option>
                        <option value ="worlofwarcraft">World of War Craft </option>
                        <option value ="forsaken">Forsaken World</option>
                        <option value ="leagueoflegends">League of Legends</option>
                        <option value ="dota">Dota 2</option>
                        <option value ="smite">Smite</option>
                        <option value ="warface">Warface</option>
                        <option value ="cs">CS-GO</option>
                        <option value ="bf">Battle Field</option>
                        <option value ="cod">Call of Dutty</option>
                    </select>
                </li>
                <li><textarea placeholder="  Mensagem" name="Mensagem" required name=mensagem></textarea></li>
                <li><input type=submit value="Enviar" id="enviar" name="Enviar"/></li>
            </ul>
        </form>
    </div>

php remembered that it is in a separate file and I am using phpmailer:

<?php
$Nome       = $_POST["Nome"];   // Pega o valor do campo Nome
$Nickname       = $_POST["Nickname"];   // Pega o valor do campo Telefone
$Email      = $_POST["Email"];  // Pega o valor do campo Email
$Mensagem   = $_POST["Mensagem"];   // Pega os valores do campo Mensagemgames
$Games  = $_POST["Games"];  // Pega os valores do campo Mensagemgames


// Variável que junta os valores acima e monta o corpo do email

$Vai        = "Nome: $Nome\n\nE-mail: $Email\n\nNicknamer: $Nickname\n\nMensagem: $Mensagem\n";

require_once("phpmailer/class.phpmailer.php");

define('GUSER', '[email protected]');   // <-- Insira aqui o seu GMail
define('GPWD', 'lalala123');        // <-- Insira aqui a senha do seu GMail

function smtpmailer($para, $de, $de_nome, $assunto, $corpo) { 
    global $error;
    $mail = new PHPMailer();
    $mail->IsSMTP();        // Ativar SMTP
    $mail->SMTPDebug = 2;       // Debugar: 1 = erros e mensagens, 2 = mensagens apenas
    $mail->SMTPAuth = true;     // Autenticação ativada
    $mail->SMTPSecure = 'ssl';  // SSL REQUERIDO pelo GMail
    $mail->Host = 'smtp.gmail.com'; // SMTP utilizado
    $mail->Port = 465;          // A porta 587 deverá estar aberta em seu servidor
    $mail->Username = GUSER;
    $mail->Password = GPWD;
    $mail->SetFrom($de, $de_nome);
    $mail->Subject = $assunto;
    $mail->Body = $corpo;
    $mail->AddAddress($para);
    if(!$mail->Send()) {
        $error = 'Mail error: '.$mail->ErrorInfo; 
        return false;
    } else {
        $error = 'Mensagem enviada!';
        return true;
    }
}

// Insira abaixo o email que irá receber a mensagem, o email que irá enviar (o mesmo da variável GUSER), 

 if (smtpmailer('[email protected]', '[email protected]', 'felipe', 'Recrutamento Nova Era', $Vai)) {

    Header("location:obrigado.html"); // Redireciona para uma página de obrigado.

}
if (!empty($error)) echo $error;
?>

OBS:the form field that I also want to appear in the email and I’m not getting it would be this:

<li>
  <select name="Games">
     <option value ="the-elder" selected>  --- Selecione um jogo ---</option>
     <option value ="the-elder">The Elder Scrols Online</option>
     <option value ="archage">ArcheAge</option>
     <option value ="worlofwarcraft">World of War Craft </option>
     <option value ="forsaken">Forsaken World</option>
     <option value ="leagueoflegends">League of Legends</option>
     <option value ="dota">Dota 2</option>
     <option value ="smite">Smite</option>
     <option value ="warface">Warface</option>
     <option value ="cs">CS-GO</option>
     <option value ="bf">Battle Field</option>
     <option value ="cod">Call of Dutty</option>
  </select>
</li>
  • You are not concatenating $Games in $Vai

  • @Lucas olaaa friend put it there as answer pa I mark as accepted because it worked

2 answers

1

Your input has two attributes name like this textarea

<textarea placeholder="  Mensagem" name="Mensagem" required name=mensagem></textarea>

If I understand correctly you want to send a select field along with your email, add this line before sending the email:

$mail->IsHTML(true);

and concatene your select to the body of the email:

$vai .= "<select name="Games"></select>";

1


You are not concatenating $Games in $Vai. Just do it like this:

$Vai = "Nome: $Nome\n\nE-mail: $Email\n\nNicknamer: $Nickname\n\nGame: $Games\n\nMensagem: $Mensagem\n";

Browser other questions tagged

You are not signed in. Login or sign up in order to post.