TheHarriets Posted August 9, 2012 Share Posted August 9, 2012 I have a website where users can e-mail advertisers via a form on the advert. The contents of the message are then e-mailed to to the advertiser. However, there are problems with the formatting: [*]apostrophes show as /' (e.g. I/'m) [*]returns don't work so there are no blank lines between paragraphs [*]if the & sign is used, anything after this is not e-mailed Here is the code of the form (I have deleted irrelevant data and changed name of site for privacy) 1 <? 2 session_start(); 3 include "includes/config.php"; 4 include_once("includes/classes.php"); 5 include_once("includes/functions.php"); 6 include_once("includes/page.inc.php"); 7 include('includes/mimemail.inc.php'); 8 include('includes/function.resize.php'); 9 $obj_db=new DB(); 10 $obj_db->open(); 11 $page=new page(); 12 include_once("includes/variables.php"); 13 $userid=$_SESSION['USERID']; 14 $userid=$_REQUEST['userID']; 15 16 17 $sql_advertiser="select *,DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(dob)), '%Y')+0 AS age from tbl_signup_user WHERE userID='".$userid."'"; 18 $rs_advertiser=mysql_query($sql_advertiser); 19 $advertiser_data=mysql_fetch_array($rs_advertiser); 20 $user_name=$advertiser_data['user_name']; 21 $settings = array('w'=>155,'h'=>185,'canvas-color'=>'#ffffff'); 22 $settings2 = array('w'=>345,'h'=>396,'canvas-color'=>'#ffffff'); 23 ?> 24 25 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 26 <html xmlns="http://www.w3.org/1999/xhtml"> 27 <head> 28 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 29 <link href="main.css" rel="stylesheet" type="text/css" /> 30 <link href="aboutme.css" rel="stylesheet" type="text/css" /> 31 32 <script type="text/javascript" src="js/events.js"></script> 33 <script type="text/javascript" src="js/tabs.js"></script> 34 <link type="text/css" media="screen" rel="stylesheet" href="css/tabs.css"> 35 36 </head> 37 38 39 <body> 40 <div id="site-container"> 41 <!--Top & middle Container Start Here--> 42 43 <div class="site_inner"> 44 <!--Header-Start--> 45 <? include "includes/header.php";?> 46 <!--Header-End--> 47 <!--Middle-Start--> 48 <div id="middlediv"> 49 50 51 <p style="padding-bottom:5px;">Email me </p> 52 53 <form id="login_form" name="login_form" method="post" action="" enctype="multipart/form-data" style="margin:0px; width:441px;"> 54 <p> 55 <label>Your name :</label> 56 <label class="inptbg"> 57 <input name="name" type="text" class="inpt2" id="name" /> 58 </label> 59 </p> 60 <p> 61 <label>Your e-mail :</label> 62 <label class="inptbg"> 63 <input name="email" type="text" class="inpt2" id="email" /> 64 </label> 65 </p> 66 <p> 67 <label>Your message :</label> 68 <label class="inptbg2"> 69 <textarea name="message" cols="" rows="" class="inpt3" id="message"></textarea> 70 </label> 71 </p> 72 <p> 73 <label>Enter the text <br /> 74 in the box :</label> 75 <!--<img src="images/capchta.gif" alt="" border="0" style="padding:5px 5px 0 0; float:left;"/>--> 76 <img src="CaptchaSecurityImages.php?width=100&height=35&characters=5" alt="" style="padding:5px 5px 0 0; float:left;" /> 77 <label class="inptbg3"> 78 <input name="security_code1" type="text" class="inpt4" id="security_code1" /> 79 </label> 80 </p> 81 <p style="padding:10px 0 0 0;"> 82 <label> </label> 83 <input type="hidden" name="action_x" value="1"> 84 <input name="btnsubmit" type="button" class="send" onclick="javascript:submitform();"/> 85 </p> 86 <div id="errordiv" style="color:#FF0000;" align="center"></div> 87 </form> 88 89 90 91 92 93 </div> 94 <!--Middle-End--> 95 </div> 96 <!--Top & middle Container End Here--> 97 </div> 98 <!--Footer-Start--> 99 <? include "includes/footer.php";?> 100 <!--Footer-End--> 101 <script language="javascript" type="text/javascript"> 102 var xmlHttp 103 104 function submitform() 105 { 106 //alert("test");return false; 107 if(validatelogin()==true) 108 { 109 xmlHttp=GetXmlHttpObject() 110 if (xmlHttp==null) 111 { 112 alert ("Browser does not support HTTP Request") 113 return 114 } 115 //alert("test");return false; 116 var url="advertiserform.php" 117 118 var poststr = "name=" + encodeURI( document.getElementById("name").value ) + 119 "&email= " + encodeURI( document.getElementById("email").value ) +"&message= " + encodeURI( document.getElementById("message").value )+ 120 "&security_code1=" + encodeURI( document.getElementById("security_code1").value )+ 121 "&advertiser_email=" + encodeURI( "<?=$advertiser_data['email']?>" )+"&advertiser_city=" + encodeURI( "<?=$advertiser_data['location']?>" ) 122 +"&advertiser_name=" + encodeURI( "<?=$advertiser_data['first_name']?>" ) 123 +"&user_name=" + encodeURI( "<?=$advertiser_data['user_name']?>" ) 124 ; 125 126 url=url+"?act=advertiser&"+poststr 127 //alert(url);return false; 128 129 xmlHttp.onreadystatechange=stateChanged 130 xmlHttp.open("GET",url,true) 131 xmlHttp.send(null) 132 } 133 } 134 135 function stateChanged() 136 { 137 //alert(xmlHttp.responseText); 138 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") 139 { 140 if(xmlHttp.responseText=="error") 141 { 142 document.getElementById("errordiv").innerHTML="Please enter correct security code." 143 } 144 else 145 { 146 document.getElementById("name").value=""; 147 document.getElementById("email").value=""; 148 document.getElementById("message").value=""; 149 document.getElementById("security_code1").value=""; 150 document.getElementById("errordiv").innerHTML="Your message has been sent." 151 //top.location.href='index.html'; 152 } 153 } 154 } 155 156 </script> 157 158 <script src="js/validation.js" language="javascript" type="text/javascript"></script> 159 <script language="javascript"> 160 function validatelogin() 161 { 162 163 if(is_empty(document.login_form.name.value)) 164 { 165 document.getElementById("errordiv").innerHTML="Please enter your name."; 166 document.login_form.name.focus(); 167 return false; 168 } 169 170 if(!is_email(document.login_form.email.value)) 171 { 172 document.getElementById("errordiv").innerHTML="Please enter valid email."; 173 document.login_form.email.focus(); 174 return false; 175 } 176 if(is_empty(document.login_form.message.value)) 177 { 178 document.getElementById("errordiv").innerHTML="Please enter your message."; 179 document.login_form.message.focus(); 180 return false; 181 } 182 if(is_empty(document.login_form.security_code1.value)) 183 { 184 document.getElementById("errordiv").innerHTML="Please enter your security code."; 185 document.login_form.security_code1.focus(); 186 return false; 187 } 188 189 return true; 190 } 191 192 </body> 193 </html> 194 <script language="javascript" type="text/javascript"> 195 function changeImage(val) 196 { 197 //alert(val); 198 document.getElementById('mainImg').src=val; 199 document.getElementById("elink").href=val; 200 } 201 </script> Here is the html of the text we add to the message: 1 <img src="http://mysite.co.uk/images/logo.png" border="0"><br /><br /> 2 Hi --first_name--,<br /><br /> 3 4 The message below was sent to you via your --user_name-- profile on the www.mysite.co.uk website. Hit reply on your e-mail to contact the sender directly.<br /><br /> 5 6 7 8 Here is the message : <br /> 9 10 From: --name--<br /> 11 Message: --message-- 12 13 <br /><br /> 14 15 16 Thanks, <br /> 17 My Site Support Does anyone have any idea please why the formatting is wrong and how I correct it? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/266880-e-mail-form-showing-strange-characters-and-not-formatting-correctly/ Share on other sites More sharing options...
Nyuszer Posted August 10, 2012 Share Posted August 10, 2012 1. http://php.net/stripslashes 2. are you using html <br /> tags for the new line or simple pressing enter? 3. this is because you are passing the message in the url, and if php gets in url ... &message=some_text&some_text1&security_code ..., $some_text1 will be a seperate variable in $_GET. you have to replace every & with stomething else in your javascript and change back to & in the php code Quote Link to comment https://forums.phpfreaks.com/topic/266880-e-mail-form-showing-strange-characters-and-not-formatting-correctly/#findComment-1368372 Share on other sites More sharing options...
Christian F. Posted August 10, 2012 Share Posted August 10, 2012 stripslashes () should not be necessary at all. Either there are some function that adds extraneous slashes in your code, or you've saved it incorrectly to the database. In either case: I can't see any code here which sends any mail, which means that we cannot help you with this issue. Please post the code responsible for retrieving the information from the AJAX query and sending the mail. Running a var_dump ($_GET) on that page, and posting the result here, might also help. That way you (and we) know, instead of guessing, what the PHP script on the other end receives. Quote Link to comment https://forums.phpfreaks.com/topic/266880-e-mail-form-showing-strange-characters-and-not-formatting-correctly/#findComment-1368377 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.