0

quisiera saber si me pueden ayudar con este código el problema que tengo es que no me llegan los correos que quiero reenviar.

Hello, I would like to know if you can help me with this code. The problem I have is that the emails I want to forward do not reach me.

Use: https://www.php.net/manual/en/function.mail.php

Codigo: Code: $inbox = imap_open(IMAP_HOSTNAME, IMAP_USERNAME, IMAP_PASSWORD) or die('Cannot connect to Gmail: ' . imap_last_error()); print_r(imap_errors());

    $MC = imap_check($inbox);
    $result = imap_fetch_overview($inbox, "1:{$MC->Nmsgs}", 0);

    foreach ($result as $overview) {
        $unixTimestamp = strtotime($overview->date);
        $fecha = date("Y-m-d H:i:s", $unixTimestamp);
        $header = imap_headerinfo($inbox, $overview->msgno);
        $desde = $header->from[0]->mailbox . "@" . $header->from[0]->host;
        $asunto = imap_utf8($overview->subject);
        $cuerpo = quoted_printable_decode(imap_fetchbody($inbox, $overview->msgno, 1));





        foreach ((array)$result as $i => $row) {
            $id = $row["id"];
            $fecha = $row["fecha"];
            $desde = $row["desde"];
            $asunto = utf8_decode($row["asunto"]);
            $cuerpo = utf8_decode($row["mensaje"]);
            
            echo 'ID: ' . $id . PHP_EOL;
            echo 'fecha: ' . $fecha . PHP_EOL;
            echo 'desde: ' . $desde . PHP_EOL;
            echo 'asunto: ' . $asunto . PHP_EOL;
            echo 'cuerpo: ' . $cuerpo . PHP_EOL;

            $to = 'email1@site.com'; 
            $subject = 'Redireccion de correo cliente';
            $headers = 'MIME-Version: 1.0';
            $headers = 'Content-type: text/html; charset=UTF-8';
            $headers = 'From: emailfrom@site.com'; 
            $headers = 'Cc: email2@site.com'; 
            $headers = 'Cc: email3@site.com';
            $message = '<html>
                        <head>
                        <title>HTML</title>
                        </head>
                        <body>
                        <h1>#{$id} - Fecha: ({$fecha}) - Desde: {$desde} Asunto: {$asunto}</h1>
                        <br><br>
                        <p>Cuerpo: $cuerpo</p>
                        </body>
                        </html>';
            mail($to, $subject, $message, $headers);

            echo "Emails have been forwarded successfully" . "\n";
        }
    } else {
        echo "There are no new emails" . "\n";
    }

Me sale el mensaje de " Emails have been forwarded successfully " como si se hubiera re enviado bien el correo pero reviso mi bandeja de entrada y no llega ni en spam

I get the message "Emails have been forwarded successfully" as if the mail had been forwarded correctly but I check my inbox and it doesn't even arrive in spam

Regards.

  • 1
    Does this answer your question? [PHP mail function doesn't complete sending of e-mail](https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail) – El_Vanja Dec 18 '20 at 12:27
  • You get the message "emails have been forwarded successfully" because your code displays it regardless of whether the `mail()` function executed properly or not - you don't check the return code from it. You should really look at using something like PHPMailer instead of the built-in `mail()` function as I believe it has many advantages. – droopsnoot Dec 18 '20 at 12:29
  • are you working on localhost or at server ? – ARVIND IT Dec 18 '20 at 12:40
  • work on a server – Auferoz Dec 18 '20 at 13:38

0 Answers0