Mail() php function, request data

Asked

Viewed 95 times

0

I did a project where I have a page of Pedidos.php that the action goes to this code below action="anexa.php".

Everything works correctly with sending to the email, but I would like to, in a page of "My orders", show an order numbering, material and quantity, for the person to know the order you made.

php attachment.

    <?php
    include("Mail.php");
    include("Mail/mime.php");

    $up = 0;

    $nome       = $_POST['nome'];
    $telefone   = $_POST['telefone'];
    $email      = $_POST['email'];
    $material   = $_POST['material'];
    $cor        = $_POST['cor'];
    $quantidade = $_POST['quantidade'];
    $acabamento = $_POST['acabamento'];
    $formato    = $_POST['formato'];
    $altura     = $_POST['altura'];
    $largura    = $_POST['largura'];
    $papel      = $_POST['papel'];
    $gramatura  = $_POST['gramatura'];
    $descricao  = $_POST['descricao'];

    $recipients = '[email protected]';

    $headers = array(
        'From' => '[email protected]',
        'To' => $recipients,
        'Subject' => "Pedido de $email"
    );

    $crlf = "\r\n";
    $text = "

    Um novo pedido foi realizado por: $nome

                   DETALHES DO PEDIDO:</br></br>

            Telefone: $telefone</br>
            Email: $email</br>
      ____________________________________</br></br>

            Material: $material</br>
            Acabamento: $acabamento</br>
            Formato: $formato</br>
            Tamanho = $altura x $largura</br>
            Cor: $cor</br>
            Papel : $papel</br>
            Gramatura: $gramatura</br>
            Quantidade: $quantidade</br></br>

            Descricoes: $descricao";
    $html = "$text";

    $mime = new Mail_mime($crlf);

    $mime->setHTMLBody($html);

    for ($i = 0; $i < count($_FILES['anexo']['name']); $i++) {

        if (is_uploaded_file($_FILES['anexo']['tmp_name'][$i])) {
            $caminho[$i] = "/home/conexaografica/www/areaderevendedor/tmp/" . $_FILES['anexo']['name'][$i];

            if (copy($_FILES['anexo']['tmp_name'][$i], $caminho[$i])) {
                $mime->addAttachment($caminho[$i]);
                unlink($caminho[$i]);
                echo "Seu arquivo foi anexado!<br>";
            }
        } else {
            echo "O arquivo não foi transferido!";
            echo "Caminho ou nome de arquivo Inválido";
        }
    }
    $body    = $mime->get();
    $headers = $mime->headers($headers);

    $params = array(
        'auth' => true,
        'host' => 'smtp.conexaografica.com.br',
        'username' => 'contato=conexaografica.com.br',
        'password' => 'conexaografica'
    );

    $mail_object = Mail::factory('smtp', $params);
    $result      = $mail_object->send($recipients, $headers, $body);
    if (PEAR::IsError($result)) {
        echo "Algo deu errado... (" . $result->getMessage() . ")";
    } else {
        echo "Seu pedido foi realizado com sucesso.";

    }
?>
  • You solve this by including more script (HTML and PHP) at the end of this code. But in this snippet you do not pass the order number.

  • I do not understand much about PHP... could help me in this matter?

1 answer

0

Try the following code instead of attaching.php

Compare the two and you will see that I put the html next to php, so that after sending the message it shows a page with the sent data or the error message.

<!DOCTYPE html>
<html>
<head><!-- copie o head de Pedidos.php, se houver --></head>
<body>
<?php // neste trecho, você deveria salvar os dados em um banco de dados
      // e assim obter um número de pedido. Daí poderá usar os dados mais
      // tarde, por exemplo, numa página de consulta de pedidos
?>

<?php
    include("Mail.php");
    include("Mail/mime.php");

    $up = 0;

    $nome       = $_POST['nome'];
    $telefone   = $_POST['telefone'];
    $email      = $_POST['email'];
    $material   = $_POST['material'];
    $cor        = $_POST['cor'];
    $quantidade = $_POST['quantidade'];
    $acabamento = $_POST['acabamento'];
    $formato    = $_POST['formato'];
    $altura     = $_POST['altura'];
    $largura    = $_POST['largura'];
    $papel      = $_POST['papel'];
    $gramatura  = $_POST['gramatura'];
    $descricao  = $_POST['descricao'];

    $recipients = '[email protected]';

    $headers = array(
        'From' => '[email protected]',
        'To' => $recipients,
        'Subject' => "Pedido de $email"
    );

    $crlf = "\r\n";
    $text = "

    Um novo pedido foi realizado por: $nome

                   DETALHES DO PEDIDO:</br></br>

            Telefone: $telefone</br>
            Email: $email</br>
      ____________________________________</br></br>

            Material: $material</br>
            Acabamento: $acabamento</br>
            Formato: $formato</br>
            Tamanho = $altura x $largura</br>
            Cor: $cor</br>
            Papel : $papel</br>
            Gramatura: $gramatura</br>
            Quantidade: $quantidade</br></br>

            Descricoes: $descricao";
    $html = "$text";

    $mime = new Mail_mime($crlf);

    $mime->setHTMLBody($html);

    for ($i = 0; $i < count($_FILES['anexo']['name']); $i++) {

        if (is_uploaded_file($_FILES['anexo']['tmp_name'][$i])) {
            $caminho[$i] = "/home/conexaografica/www/areaderevendedor/tmp/" . $_FILES['anexo']['name'][$i];

            if (copy($_FILES['anexo']['tmp_name'][$i], $caminho[$i])) {
                $mime->addAttachment($caminho[$i]);
                unlink($caminho[$i]);
                echo "Seu arquivo foi anexado!<br>";
            }
        } else {
            echo "O arquivo não foi transferido!";
            echo "Caminho ou nome de arquivo Inválido";
        }
    }
    $body    = $mime->get();
    $headers = $mime->headers($headers);

    $params = array(
        'auth' => true,
        'host' => 'smtp.conexaografica.com.br',
        'username' => 'contato=conexaografica.com.br',
        'password' => 'conexaografica'
    );

    $mail_object = Mail::factory('smtp', $params);
    $result      = $mail_object->send($recipients, $headers, $body);
    if (PEAR::IsError($result)) {
        echo "Algo deu errado... (" . $result->getMessage() . ")";
    } else {            
        echo("<P>$nome, Seu pedido foi realizado com sucesso.</P>". 
        "<P align="center">DETALHES DO PEDIDO:</P>".
        "<P>Telefone: $telefone <br>".
        "Email: $email <br>".
        "____________________________________</P>".
        "<P>Material: $material <br>".
        "Acabamento: $acabamento <br>".
        "Formato: $formato <br>".
        "Tamanho = $altura x $largura <br>".
        "Cor: $cor <br>".
        "Papel : $papel <br>".
        "Gramatura: $gramatura <br>".
        "Quantidade: $quantidade</P>";          
    }
?>  
</body>
</html>
  • Apart from the successful order submission page, can this data be printed in another? Sorry it takes, it’s just that I’ve been away!

  • If I understand the flow, the user fills in a form. and when clicking on the "ok" button, an email message is sent with any attachments. I just showed you how to display the data sent on the success screen. To take this data to another page, you need to save the data.

  • I did not put to go to the database, because this part of the request, has many options within some select.

  • I do not understand much, I do not know if this way with the function mail, has to continue only that in the same way to send to the bank

  • The logic of the program should be to record the data before doing anything else with it. HTML has not been, that is, it does not store any information automatically, you must save specifically. That is, after clicking the <ok> button, the script must save the data in a database that in turn will generate a registration number (ID) that you can use as the order number if you want. Only then, you should send the email and send the data to the "success" screen. I put a comment (//) in the code, where the data should be saved.

  • Thank you for your attention my friend, I’ll do that and I’ll get back to you.

  • Good my friend, The data is not being sent to the bank, and no error message appears.

  • Sorry buddy, now I got it, it’s all right, sending to the bank, and to the email, and I put to generate a random number, which is printed on the screen, sent to the email and sent to the bank, the same number. Now my doubt is how to assemble the area of my requests with the request of the specific person, can not risk coming request of another person? how it’s all going to the same bank. I don’t know exactly how I should do, as I said I don’t understand much.

  • @Erickfaria, I think the idea of this forum is to stay focused. Sometimes, the answer is not exactly what we wanted, but it opens the way to find the solution, and also opens new questions. I think this is a case like this. You’ve learned that it’s not enough to send the email, it has a whole stream to follow. Now, do a little research on this, try new codes and bring new questions. Or, take this question you asked above and generate a new one.

Show 4 more comments

Browser other questions tagged

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