registration confirmation via email

3

I am putting together a registration system and only the part of the confirmation in the email is missing to finish and I am not able to do this part. I already searched for tutorials on youtube and tried to apply them to my code, but that does not work, could anyone help me?

<?php

if(isset($_POST['cadastrar']) && $_POST ['cadastrar'] == "register")
{
    $nome = $_POST['nome'];
    $sobrenome = $_POST['sobrenome'];
    $data = $_POST['data'];
    $cpf = $_POST['cpf'];
    $email = $_POST['email'];
    $pais = $_POST['pais'];
    $estado = $_POST['estado'];
    $login = $_POST['login'];
    $senha = $_POST['senha'];
    $rsenha = $_POST['rsenha'];
    $image = $_FILES['image']['name'];

    if(empty($nome) || empty($sobrenome) || empty($data) || empty($cpf) || empty($email) ||  empty($pais) || empty($estado) || empty($login) || empty($senha) || empty($rsenha) || ($cpf_enviado == false) || (@$emailvalida == false))

        {

        }else{
            $query = "SELECT * FROM cadastro WHERE login = '$login'";
            $result = mysql_query($query);
            $conta = mysql_num_rows($result);
            $busca = mysql_fetch_assoc($result);

            if($conta > 0){
                echo '<div id="preencha" style="width:200px; position:relative; left:580px; top:-30px; color:#fff; font-size:15px; ">Usuário já cadastrado!</div>   ';
            }else{
                $cadastrar = "INSERT INTO cadastro (nome, sobrenome, data, cpf, email, pais, estado, login, senha, rsenha, image)
                             VALUES ('$nome', '$sobrenome', '$data', '$cpf', '$email', '$pais', '$estado', '$login', '$senha', '$rsenha', '$image')";
                if(mysql_query($cadastrar))
                {
                    $_SESSION['nome'] = $nome;
                    $_SESSION['sobrenome'] = $sobrenome;
                    $_SESSION['data'] = $data;
                    $_SESSION['cpf'] = $cpf;
                    $_SESSION['email'] = $email;
                    $_SESSION['pais'] = $pais;
                    $_SESSION['estado'] = $estado;
                    $_SESSION['login'] = $login;
                    $_SESSION['senha'] = $senha;    
                    $_SESSION['rsenha'] = $rsenha;
                    $_SESSION['image'] = $image;

                    echo "<script type=\"text/javascript\">window.setTimeout(\"location.href='cadastroRealizado.php';\");</script>";
                }
                else
                {
                    echo '<div id="preencha" style="width:200px; position:relative; left:580px; top:-30px; color:#fff; font-size:15px; ">Erro ao cadastrar!</div>';
                }

                $conexaoemail = mysql_query("SELECT * FROM cadastro WHERE nome = '$nome'");
                $resultado = mysql_fetch_array($conexaoemail);
                $id = $resultado['id'];

                $assunto = "Ative sua conta";
                $mensagem = "Ative sua conta clicando no link:";
                $headers = "[email protected]";
                $email = $_POST['email'];
                mail($email, $assunto, $mensagem, $headers);

            }
        }
    }


?>
    
asked by anonymous 03.04.2017 / 21:38

2 answers

1

I've removed this good example from the official PHP website:

<?php
$to      = '[email protected]';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

This second example is more elegant:

<?php
// Multiple recipients
$to = '[email protected], [email protected]'; // note the comma

// Subject
$subject = 'Birthday Reminders for August';

// Message
$message = '
<html>
<head>
  <title>Birthday Reminders for August</title>
</head>
<body>
  <p>Here are the birthdays upcoming in August!</p>
  <table>
    <tr>
      <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
    </tr>
    <tr>
      <td>Johny</td><td>10th</td><td>August</td><td>1970</td>
    </tr>
    <tr>
      <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
    </tr>
  </table>
</body>
</html>
';

// To send HTML mail, the Content-type header must be set
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';

// Additional headers
$headers[] = 'To: Mary <[email protected]>, Kelly <[email protected]>';
$headers[] = 'From: Birthday Reminder <[email protected]>';
$headers[] = 'Cc: [email protected]';
$headers[] = 'Bcc: [email protected]';

// Mail it
mail($to, $subject, $message, implode("\r\n", $headers));
?>

Source: link

    
03.04.2017 / 22:52
-1

Forget the mail function, use PHPMailer PHPMailer

follow example

require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug =2;// 0,1 ou 2
$mail->Debugoutput = 'html';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Username = "[email protected]";
$mail->Password = "senha";
$mail->CharSet = 'UTF-8';
$mail->setFrom('[email protected]', 'Informativo');
$mail->addAddress('[email protected]', 'algum texto');
$mail->addAddress('[email protected]', 'algum texto');
$mail->addAddress('[email protected]', 'algum texto');
$mail->Subject = 'assunto do email';

$mensagem = 'Teste teste teste ';
$mensagem .= 'outro teste';

$mail->msgHTML($mensagem);

$mail->AltBody = 'Caso você esteja lendo essa mensagem é provável que seu cliente de email não tenha suporte a HTML';
if (!$mail->send()){
    echo "email NÃO enviado";
}else {
    echo "email enviado com sucesso";
}
    
24.04.2018 / 01:12