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.