View Full Version : Junk appearing in variable via mail

07-18-2008, 06:02 PM
I have an e-mail script setup which outputs links depending on what options someone selects from a web form. Lately, I have been seeing junk output coming from my variable. For instance, one of the links that is outputted displays in the e-mail as:


It is inserting the '!%0a+' from somewhere and I cannot figure out where.

I am using simple if statements to build a $msg variable:

if ($item1==true) { $msg = "http://files.brandtalexander.com/pdf/newsletter1.pdf"; }
if ($item2==true) { $msg .= "http://files.brandtalexander.com/pdf/newsletter2.pdf"; }

and so on...

My email code is:

$headers = "From: $email\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
mail($to, $hostsub, $hostmsg, $headers);

I setup to have it echo the $msg and it is perfectly fine. The error only appears in the email itself. I have tested this with a variety of e-mail clients. What could be causing this? Thank you in advance.

07-21-2008, 02:54 PM
I still cannot figure out why this is happening. Can anyone provide some insight? Thanks.

07-29-2008, 10:24 PM
I was able to test this script on another server and had no issues at all. What could cause something like to happen all of a sudden? Did my host change a setting or some software? Any insight will be appreciated. Thank you.

07-29-2008, 11:13 PM
could be something with the php mail function. But i cant figure it out, it comes out ok here. Can you post the whole script and ill look over it a little more.

07-30-2008, 08:19 PM
This is the code my form posts to. My host said there was an issue with some of the PHP extensions, but theyfixed them and the problem stills persists. You will find my code below (i took out all my form validation code to shorten it up). recipient, subject, domain and broch1, 2, etc are all passed from the originating form.


$path2pdf = $_POST['domain'] . "ebrochures/";

//sends email to home
$to = $recipient;
$date = date("m/d/Y");
$time = date("h:i:s A");
$hostsub = "eBrochure request";
$hostmsg = "<strong>Feedback from website:</strong><br />
Name: $name<br />
Occupation: $occupation<br />
Address: $address<br />
City: $city<br />
State: $state<br />
Zip: $zip<br />
Country: $country<br />
E-Mail: $email<br />
Phone: $phone<br /><br />
Comments: $comments <br /><br />
<b>Requested Brochures:</b> <br />";

$brochmsg =($_POST['broch1'])?"<a href=\"".$path2pdf."ebrochure_01.pdf\">eBrochure #01</a><br>":"";
$brochmsg .=($_POST['broch2'])?"<a href=\"".$path2pdf."ebrochure_02.pdf\">eBrochure #02</a><br>":"";
$brochmsg .=($_POST['broch3'])?"<a href=\"".$path2pdf."ebrochure_03.pdf\">eBrochure #03</a><br>":"";

//combine host and brochure message
$hostmsg .= $brochmsg;
$hostmsg = stripslashes($hostmsg);

$headers = "From: $email\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
mail($to, $hostsub, $hostmsg, $headers);

//sends email to user
$to = $email;
$hostmsg = "";
$hostmsg = "Thank you $name for requesting our eBrochures! Below you will find the links directing you to the PDF versions of our eBrochures that you requested.<br /><br />";
$hostmsg .= "<b>eBrochures:</b><br />";
$hostmsg .= $brochmsg;
$hostmsg = stripslashes($hostmsg);

$headers = "From: $recipient\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
mail($to, $subject, $hostmsg, $headers);
header("Location: ".$_SERVER['PHP_SELF']."?action=sent");