How do I send including the database id in the email?

Asked

Viewed 27 times

-1

I tried that way but of the undifined index.

php-based.

<?php  

    $conexao=mysqli_connect('localhost', 'root','','formulario');

    mysqli_set_charset($conexao,'utf');

    if ($conexao->connect_error) {
        die("Falha ao efectuar ligação: ".$conexao->connect_error);

    }
?>

php sending.

<?php 
  include "basededados.php";

  if(isset($_POST['upload'])){

    $nome = $_POST['nome'];
    $processo=$_POST['processo']; 
    $email = $_POST['email'];
    $disciplina=$_POST['disciplina']; 

    $sql= "INSERT INTO dados VALUES ('','$nome','$processo','$email','$disciplina')";

    mysqli_query($conexao, $sql);
 }

?>

<?php

    include "basededados.php";

    $mailto = $_POST['mailto'];
    $mailSub = $_POST['mailsub'];
    $id = $_GET['id'];
    $escola=$_POST['escola']; 
    $nome = $_POST['nome'];
    $processo=$_POST['processo']; 
    $disciplina=$_POST['disciplina']; 


   require 'PHPMailer-master/PHPMailerAutoload.php';
   $mail = new PHPMailer();
   $mail ->IsSmtp();
   $mail ->SMTPDebug = 0;
   $mail ->SMTPAuth = true;
   $mail ->SMTPSecure = 'ssl';
   $mail ->Host = "smtp.gmail.com";
   $mail ->Port = 465; // or 587
   $mail ->IsHTML(true);                
   $mail ->Username = "[email protected]";
   $mail ->Password = "password";          
   $mail ->SetFrom("[email protected]");
   $mail ->Subject = $mailSub;
   $mail ->Body='<h2>$id.Escola: '.$_POST['escola'].'<br>Nome: '.$_POST['nome'].'<br>Processo: '.$_POST['processo'].'<br>Email: '.$_POST['email'].'<br>Disciplina: '.$_POST['disciplina'].$id.'</h2>';
   $mail ->AddAddress($mailto);

   if(!$mail->Send())
   {
       echo "Pedido não foi enviado.<br>";
   }
   else
   {
       echo "Pedido enviado com sucesso!<br>";
   }
      $mail->ClearAddresses();
?>
  • You want the Insert ID you just made and put in the email?

  • yes but I’m having a hard time calling you

  • 1

    If the error is "Undefined index" you are accessing a position that does not exist from an array and has no relation to the connection to the database or sending email. It manages to elaborate a [mcve]?

  • now ta appearing Undefined variable

  • In relation to this notice undefined This link might help you Variable errors at the beginning of PHP

1 answer

0


I put the answer in the example you posted,

Important: Do not include the same file twice.

the function mysqli_insert_id($conexao) returns the id of the last query made by the connection

<?php 
  include "basededados.php";

  if(isset($_POST['upload'])){

    $nome = $_POST['nome'];
    $processo=$_POST['processo']; 
    $email = $_POST['email'];
    $disciplina=$_POST['disciplina']; 

    $sql= "INSERT INTO dados VALUES ('','$nome','$processo','$email','$disciplina')";

    mysqli_query($conexao, $sql);

    $ultimo_id = mysqli_insert_id($conexao);
 }

?>

<?php
    //Não pode incluir duas vezes o mesmo arquivo
    //include "basededados.php";


  • That was it, I wanted to know how to call the last id thank you

Browser other questions tagged

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