SEVIZ Posted April 15, 2009 Share Posted April 15, 2009 I am submitting a form and sending it to an email with no issues except for one. When sent there is a big space at the top of the message before the actual content appears. This is a big issue because the messages being sent have a 160 character limit. So the space is taking up most of the content area. What am I missing? Code being used: <?php if ($_POST["email"]<>'') { $ToEmail = 'emailhere'; $EmailSubject = $_POST["subject"]."\r\n"; $mailheader = "From: ".$_POST["email"]."\r\n"; $MESSAGE_BODY = $_POST["comment"]."\r\n"; mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); ?> Your Text has been sent. Any replies will go to:<?php echo $_POST["email"]; ?> <?php } else { ?> <form action="test.php" method="post"> <table width="400" border="0" cellspacing="2" cellpadding="0"> <tr> <td width="29%" class="bodytext">Subject:</td> <td width="71%"><input name="subject" type="text" id="name" size="32"></td> </tr> <tr> <td class="bodytext">Message:</td> <td><textarea name="comment" cols="45" rows="6" id="comment" class="bodytext"></textarea></td> </tr> <tr> <td class="bodytext">Email address:</td> <td><input name="email" type="text" id="email" size="32"></td> </tr> <tr> <td class="bodytext"> </td> <td align="left" valign="top"><input type="submit" name="Submit" value="Send"></td> </tr> </table> </form> <?php }; ?> Quote Link to comment https://forums.phpfreaks.com/topic/154261-email-sent-via-php-problem/ Share on other sites More sharing options...
nankoweap Posted April 15, 2009 Share Posted April 15, 2009 have you tried trimming the comment? something like: $MESSAGE_BODY = trim($_POST["comment"]) . "\r\n"; jason Quote Link to comment https://forums.phpfreaks.com/topic/154261-email-sent-via-php-problem/#findComment-810995 Share on other sites More sharing options...
SEVIZ Posted April 15, 2009 Author Share Posted April 15, 2009 Yes I tried that and the space remains. I did just realize I left out a very important piece of information. If I send the information to a standard email the message appears fine. But if I send to a phone via a text message the space is there. However, if I email from my email to the text on the phone there is no space. So I know its not the messaging service adding a space. It must be something with this script I just cannot see. Quote Link to comment https://forums.phpfreaks.com/topic/154261-email-sent-via-php-problem/#findComment-810999 Share on other sites More sharing options...
nankoweap Posted April 15, 2009 Share Posted April 15, 2009 It must be something with this script I just cannot see. or it could simply be how each reader interprets the original message. is it possible for your code to send the same message to multiple recipients? then you'll get confirmation of how each reader interprets the same message. jason Quote Link to comment https://forums.phpfreaks.com/topic/154261-email-sent-via-php-problem/#findComment-811057 Share on other sites More sharing options...
premiso Posted April 16, 2009 Share Posted April 16, 2009 <?php // changed this to be a better check thata it is not empty if (isset($_POST["email"]) && !empty($_POST["email"])) { $ToEmail = 'emailhere'; $EmailSubject = trim($_POST["subject"]); // \r\n should only be for mail headers. Nothing else. $mailheader = "From: ".$_POST["email"]."\r\n"; $MESSAGE_BODY = trim($_POST["comment"]); // trim any whitespaces there may be in the body mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); ?> Your Text has been sent. Any replies will go to:<?php echo $_POST["email"]; ?> <?php } else { ?> <form action="test.php" method="post"> <table width="400" border="0" cellspacing="2" cellpadding="0"> <tr> <td width="29%" class="bodytext">Subject:</td> <td width="71%"><input name="subject" type="text" id="name" size="32"></td> </tr> <tr> <td class="bodytext">Message:</td> <td><textarea name="comment" cols="45" rows="6" id="comment" class="bodytext"></textarea></td> </tr> <tr> <td class="bodytext">Email address:</td> <td><input name="email" type="text" id="email" size="32"></td> </tr> <tr> <td class="bodytext"> </td> <td align="left" valign="top"><input type="submit" name="Submit" value="Send"></td> </tr> </table> </form> <?php } ?> Made use of trim also removed some \r\n after the subject and body as it is only needed for headers. See if this helps. Quote Link to comment https://forums.phpfreaks.com/topic/154261-email-sent-via-php-problem/#findComment-811090 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.