1
function boletin_envio($asunto,$mensaje) {
global $pref,$db,$IndexUrl,$TituloWeb,$EmailWeb;

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$cuerpo = '<html><body>';
$cuerpo .="X: \n\n";
$cuerpo.="Asunto: $asunto \n";
$cuerpo.="Mensaxe: \n";
$cuerpo.="$mensaje \n\n";
$cuerpo.="$IndexUrl \n\n";
$cuerpo .= '</body></html>';
$sql = "SELECT X FROM ".$pref."X WHERE X='X'";
if($resultado = $db->sql_query($sql)) {
    $total = $db->sql_numrows($resultado);
    while($row = $db->sql_fetchrow($resultado)) {
        mail("$row[Login]", "$asunto", "$cuerpo", "From: X <$EmailWeb>", "$headers");
    }
    $db->sql_freeresult($resultado);
}

echo ("<script>window.open('X','_self')</script>");
}

I have this code, and I'm trying to figure it out so it can work with html tags, I'm pretty sure I'm doing something wrong but don't know what. The user writes the message in a ckeditor.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
JaneDoe
  • 39
  • 6
  • I'm getting the message with MESSAGE – JaneDoe Oct 24 '19 at 16:10
  • `\n` isn't meant to be line breaks in HTML, use `
    ` tags. Edit: (I deleted my previous comment similar to this, sorry).
    – Funk Forty Niner Oct 24 '19 at 16:11
  • `mail("$row[Login]", "$asunto", "$cuerpo", "From: X <$EmailWeb>", "$headers");` - Remove the quotes from all of these except the 3rd argument. `mail($row[Login], $asunto, $cuerpo, "From: X <$EmailWeb>", $headers);` - Try that and what I mentioned above and see what that gives you. Or something like that, the `$row` array is tricky and might need to be quoted also. – Funk Forty Niner Oct 24 '19 at 16:15
  • Okay, so I tried it, and it's the same I also changed already the \n for
    except for the headers
    – JaneDoe Oct 24 '19 at 16:19
  • [See this answer](https://stackoverflow.com/a/11239033/1415724) on sending HTML email and base yourself on that. There should be a proper `From: email...` in there and your method might be failing silently because of it. – Funk Forty Niner Oct 24 '19 at 16:21
  • there is a <$EmailWeb> in the From – JaneDoe Oct 24 '19 at 16:25
  • Okay I see the problem, defining the from in the header worked, don't know if it was something else but at the end it was pretty much the same. Thx. Do you answer to it? or how I close the post??? $headers = "From: x <$EmailWeb>\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; mail($row[Login], $asunto, $cuerpo, $headers); – JaneDoe Oct 24 '19 at 16:58

1 Answers1

0

It's best to use From: in the mail's headers in order to tell the receiver that the email does come from an E-mail address and this in turn could have adverse effects during the process.

Many times, it will either be rejected or not properly formatted to fix within the mail's arguments, in turn failing silently.

As outlined (HTML examples) in the manual for mail().

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141