PDA

View Full Version : No spaces on Email received by PHP form


Ricky55
07-03-2008, 07:39 PM
following from my last post, my form i sending me a message via SMS text but due to the spaces its creating its chopping half the message off due to the constraints of the service.

The email / text I get looks like this:

Name: test

Address: sshshsh

Postcode: sdhdhhd

Email: richard@qwk

Vehicle: jsjsjsj

Damage: sjsjjsj

Contact: 16464

The script is a PHP script, is it possible to set it up so it doesn't create the spaces and just writes one line straight after the previous.

The scrtipt


<?php
$after = "thanks.html";
$oops = "oops.html";

if (!isset($_POST['submit']) || $_SERVER['REQUEST_METHOD'] != "POST") {
exit("<p>You did not press the submit button; this page should not be accessed directly.</p>");
} else {
$exploits = "/(content-type|bcc:|cc:|document.cookie|onclick|onload|javas cript|alert)/i";
$profanity = "/(beastial|bestial|blowjob|clit|cock|cum|cunilingus |cunillingus|cunnilingus|cunt|ejaculate|fag|felati o|fellatio|****|fuk|fuks|gangbang|gangbanged|gangb angs|hotsex|jism|jiz|kock|kondum|kum|kunilingus|or gasim|orgasims|orgasm|orgasms|phonesex|phuk|phuq|p orn|pussies|pussy|spunk|xxx)/i";
$spamwords = "/(viagra|phentermine|tramadol|adipex|advai|alprazol am|ambien|ambian|amoxicillin|antivert|blackjack|ba ckgammon|texas|holdem|poker|carisoprodol|ciara|cip rofloxacin|debt|dating|porn)/i";
$bots = "/(Indy|Blaiz|Java|libwww-perl|Python|OutfoxBot|User-Agent|PycURL|AlphaServer)/i";

if (preg_match($bots, $_SERVER['HTTP_USER_AGENT'])) {
exit("<p>Known spam bots are not allowed.</p>");
}
foreach ($_POST as $key => $value) {
$value = trim($value);

if (empty($value)) {
exit("<p>Empty fields are not allowed. Please go back and fill in the form properly.</p>");
} elseif (preg_match($exploits, $value)) {
exit("<p>Exploits/malicious scripting attributes aren't allowed.</p>");
} elseif (preg_match($profanity, $value) || preg_match($spamwords, $value)) {
exit("<p>That kind of language is not allowed through our form.</p>");
}

$_POST[$key] = stripslashes(strip_tags($value));
}

if (!ereg("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,6})$",strtolower($_POST['email']))) {
exit("<p>That e-mail address is not valid, please use another.</p>");
}

$recipient = "jasonhutchinson32@btinternet.com";
$subject = "Web Site Enquiry";

$message = "You've received an e-mail through your website form: \n\n";
$message .= "Name: {$_POST['name']} \n\n";
$message .= "Address: {$_POST['address']} \n\n";
$message .= "Postcode: {$_POST['postcode']} \n\n";
$message .= "Email: {$_POST['email']} \n\n";
$message .= "Vehicle: {$_POST['vehicle']} \n\n";
$message .= "Damage: {$_POST['damage']} \n\n";
$message .= "Contact: {$_POST['contact']} \n\n";


$headers = "From: <{$_POST['email']}> \n";
$headers .= "Reply-To: <{$_POST['email']}>";

if (mail($recipient,$subject,$message,$headers)) {
echo "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=$after\">";
} else {
echo "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=$oops\">";
}
}
?>

edbr
07-04-2008, 01:06 AM
in example
$message .= "Address: {$_POST['address']} \n\n";
\n\n
is creating 2 new lines befor printing the next line delete to taste!
If i have understood your question correctly

Ricky55
07-04-2008, 07:52 AM
You have mate, I don't understand PHP, if that will get rid of the line spaces then this is it.