-2

I have a 15 letter code that seems to add itself at the end of emails I send.

enter image description here

This code seems to change every email batch I send (if I send multiple emails via a loop, they all have the same code, but next time I send multiple emais, the code is different) and the code always seem to be 15 characters.

So does anybody know where this code might be coming from, and how to prevent it?

I'm using the default PHP mail() function.

Edit:

Heres a snippet of the code generating the Email.

$boundary = uniqid('np');
$headers =  'From: This.Site <no-reply@This.Site>' . "\r\n" .
                'Reply-To: no-reply@This.Site' . "\r\n" .
                "MIME-Version: 1.0" . "\r\n" .
                "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n".
                'X-Mailer: PHP/' . phpversion();

mail($email, 'Subject - '.$title.' - Client Name', create_notif_email($name, $compagnieFrom, $title, $link, $boundary), $headers);

function create_notif_email($name, $compagnieFrom, $title, $link, $boundary){
    $urlSite = get_bloginfo('url');
    $html = '';
    $html .= file_get_contents(__DIR__.'/plaintext.txt');
    $html .= "\r\n\r\n--" . $boundary . "\r\n";
    $html .= "Content-type: text/plain;charset=utf-8\r\n\r\n";
    $html .= file_get_contents(__DIR__.'/plaintext.txt');
    $html .= "\r\n\r\n--" . $boundary . "\r\n";
    $html .= "Content-type: text/html;charset=utf-8\r\n\r\n";
    $html .= file_get_contents(__DIR__.'/mail.html');
    $html .= $boundary;
    $html = str_replace('[NOM]', $name, $html);
    $html = str_replace('[FROM]', $compagnieFrom, $html);
    $html = str_replace('[TITLE]', $title, $html);
    $html = str_replace('[LINK]', '<a href="'.$link.'">'.$link.'</a>', $html);
    $html = str_replace('[URLSITE]', $urlSite, $html);
    return $html;
}

mail.html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Nouveau poste pour vous! - [TITLE] - Bestaff</title>
</head>
<body style="width:100%; margin:0; padding:0; -webkit-text-size-adjust:100%; -ms-text-size-adjust:100%;">

<!-- body wrapper -->
<table cellpadding="0" cellspacing="0" border="0" style="margin:0; padding:0; width:100%; line-height: 100% !important;">
  <tr>
    <td valign="top">
      <!-- edge wrapper -->
<!-- ///////////////////////////////////////////////////// -->

<table cellpadding="0" cellspacing="0" border="0" align="center">
  <tr>
    <td width="20"></td>
    <td valign="top" style="vertical-align: top; text-align:left;">
      <br /><img src="[URLSITE]/images/image.png" alt="Bestaff.in" title="Bestaff.in"/><br />
      <div style="font-family:Arial, sans-serif; font-size:14px; line-height:18px;">
        <br /><i>English version follows</i><br /><br />
        Bonjour [NOM],<br /><br />
        [FROM] [TITLE].<br /><br />
        [LINK]<br /><br />
        Bonne chance!<br /></br>
        <i style="font-style=12px"></i>
        <br />&nbsp;<hr /><br />
        Hello [NOM],<br /><br />
        [FROM][TITLE].<br /><br />
        [LINK]<br /><br />
        Good luck!<br /></br>
        <i style="font-style=12px"></a></i><br />
        &nbsp;
    </div>
    </td>
    <td width="20"></td>
  </tr>
</table>

    </td>
  </tr>
</table>
<!-- / page wrapper -->
</body>
</html>

and plaintext.txt

English version follows

Bonjour [NOM],
[FROM][TITLE].
[LINK]
Bonne chance!

Hello [NOM],
[FROM][TITLE].
[LINK]
Good luck!
Fredy31
  • 2,660
  • 6
  • 29
  • 54
  • 1
    Can we see your code? – Professor Zoom Sep 02 '16 at 19:40
  • So you want a code to do random chars every time that an email been sent ? – Laith Sep 02 '16 at 19:40
  • No I want to prevent the code from showing up – Fredy31 Sep 02 '16 at 19:41
  • lol i guess i did , @Fredy31 can we see the code plz ? Ok never mind had to read the Q many times to get it – Laith Sep 02 '16 at 19:42
  • "I have a 15 letter code" where? can you show that part? I mean the code that is generating those random letters – Professor Zoom Sep 02 '16 at 19:47
  • Edits: Have added my code, cut a little bit to keep anonymity of the project. As you can see I dont have a 'Generate random 15 letters' function in the code :p – Fredy31 Sep 02 '16 at 19:48
  • @ProfessorZoom its in the screenshot at the top. The np57 part – Fredy31 Sep 02 '16 at 19:48
  • You could try making your html a bit more valid first and see if that helps. Seems like a part of your header could be leaking in because of the poorly-formatted tags. – Blake Sep 02 '16 at 19:50
  • Why `style="font-style=12px"?` change `=` to `:` like this `style="font-style: 12px"` – Professor Zoom Sep 02 '16 at 19:50
  • Have you tried `echo create_notif_email($name, $compagnieFrom, $title, $link, $boundary); die();` instead of calling `mail()`? This will help you identify if the issue is in your subject line or further down the line. It is quite possible that your hosting provided is added the random characters. It is also possible that your HTML is getting fubarred by the email client which tries to make your email safe for viewing. – MonkeyZeus Sep 02 '16 at 19:54
  • Your code is prone to being easily broken. What happens when `$link` has `[URLSITE]` inside of it? I'll tell you what happens, the next `str_replace()` is going to mistakenly replace it. – MonkeyZeus Sep 02 '16 at 19:56
  • It's either getting added by your code, or by the email server you're going through. So change your code to just send an empty email, and see if the 15 character thing is still there. If so, then someone is modifying your email after PHP is done with it. – Andy Lester Sep 02 '16 at 19:57
  • To avoid your `str_replace()` weakness, I suggest looking at this [**answer**](http://stackoverflow.com/a/36317407/2191572) and getting familiar with [**strtr()**](http://php.net/manual/en/function.strtr.php) – MonkeyZeus Sep 02 '16 at 19:59

1 Answers1

1

Boundary id typically start with double dash and are followed immediatly by a line break Try this.... Change

 $html .= $boundary;

to

$html .= '--'.$boundary.'
';

source:https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html

Duane Lortie
  • 1,285
  • 1
  • 12
  • 16
  • to fully answer your question.. "So does anybody know where this code might be coming from", Yes, it comes from $boundary = uniqid('np'); // $boundry is appened to the message and how to prevent it?"// Yes, see my answer above and or the referenced W3.org page – Duane Lortie Sep 02 '16 at 20:07