Jump to content

Recommended Posts

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 
}; 
?>

Link to comment
https://forums.phpfreaks.com/topic/154261-email-sent-via-php-problem/
Share on other sites

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.

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

<?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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.