Page 1 of 1
Correct mime type for contact form
Posted: Sat Jan 12, 2008 5:52 am
by Fredy
I have bin getting "\r\n" symbols in my mails instead of a text going in a new line.
Iwwas told that I dont have a correct MIME TYPE but I do not know how to fix this prblem.
The script I'm using is:
Code: Select all
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$email = mysql_prep($_REQUEST['email']) ;
$subject = mysql_prep($_REQUEST['subject']) ;
$message = mysql_prep($_REQUEST['message']) ;
$message = wordwrap($message);
mail( "alfred.vizintin@pu.t-com.hr", "Subject: $subject",
$message, "From: $email" );
echo "Hvala što ste koristili našu internet formu";
}
else
//if "email" is not filled out, display the form
{
echo "<form method='post' action='kontakt.php'>
Vaš e-mail: <input name='email' type='text' /><br />
Naslov: <input name='subject' type='text' /><br />
Poruka:<br />
<textarea name='message' rows='12' cols='30'>
</textarea><br />
<input type='submit' value='Pošalji'/>
</form>";
}
?>
and the header in my html document is:
<meta http-equiv="Content-Type: text/html; charset=iso-8859-1\n" />
Thanks
Re: Correct mime type for contact form
Posted: Sat Jan 12, 2008 7:03 am
by vigge89
Try using str_replace to replace all occurences of \r\n and \r with \n;
Code: Select all
$string = str_replace(array("\r\n", "\r"), "\n", $string);
Re: Correct mime type for contact form
Posted: Sat Jan 12, 2008 10:42 am
by Fredy
I put the function str_replace on text but it didn't work.
<?php
$message = str_replace(array("\r\n", "\r"), "\n", $message);
?>
I was told that the problem is with the MIME type.
That I shuld change somethin there but I just don't know what.
Re: Correct mime type for contact form
Posted: Sat Jan 12, 2008 11:01 am
by RobertGonzalez
Try doing a var_dump() on $message before mailing it and see what is in there. There is a chance that the mysql_prep function might be doing something to it. wordwrap(), be default, will also add a "\n" new line char at the end of the line by defualt.
Re: Correct mime type for contact form
Posted: Sat Jan 12, 2008 11:13 am
by Fredy
Everah | Please use the correct [code] bbcode tag when posting code in the forums.
var_dump() didn' help. It outputs the content back on the page and the message was not sent.
My mysql_prep function look licke this:
Code: Select all
mysql_prep( $value ) {
$magic_quotes_active = get_magic_quotes_gpc();
$new_enough_php = function_exists( "mysql_real_escape_string" ); // i.e. PHP >= v4.3.0
if( $new_enough_php ) { // PHP v4.3.0 or higher
// undo any magic quote effects so mysql_real_escape_string can do the work
if( $magic_quotes_active ) { $value = stripslashes( $value ); }
$value = mysql_real_escape_string( $value );
} else { // before PHP v4.3.0
// if magic quotes aren't already on then add slashes manually
if( !$magic_quotes_active ) { $value = addslashes( $value ); }
// if magic quotes are active, then the slashes already exist
}
return $value;
}
Everah | Please use the correct [code] bbcode tag when posting code in the forums.
Re: Correct mime type for contact form
Posted: Sat Jan 12, 2008 12:40 pm
by RobertGonzalez
Fredy wrote:var_dump() didn' help. It outputs the content back on the page and the message was not sent.
Everah wrote:Try doing a var_dump() on $message before mailing it and see what is in there. There is a chance that the mysql_prep function might be doing something to it.
That was the point, not to send the message but to see the message as PHP sees it.
Fredy wrote:My mysql_prep function look licke this:
Code: Select all
mysql_prep( $value ) {
$magic_quotes_active = get_magic_quotes_gpc();
$new_enough_php = function_exists( "mysql_real_escape_string" ); // i.e. PHP >= v4.3.0
if( $new_enough_php ) { // PHP v4.3.0 or higher
// undo any magic quote effects so mysql_real_escape_string can do the work
if( $magic_quotes_active ) { $value = stripslashes( $value ); }
$value = mysql_real_escape_string( $value );
} else { // before PHP v4.3.0
// if magic quotes aren't already on then add slashes manually
if( !$magic_quotes_active ) { $value = addslashes( $value ); }
// if magic quotes are active, then the slashes already exist
}
return $value;
}
I wouldn't guess this would be causing it. What platform is your server?
Re: Correct mime type for contact form
Posted: Sat Jan 12, 2008 1:41 pm
by Fredy
the web hosting is on Linux.
Re: Correct mime type for contact form
Posted: Sat Jan 12, 2008 2:08 pm
by RobertGonzalez
So are you developing locally and testing before deploying to the server or are you coding and then FTPing to the server to test?
Re: Correct mime type for contact form
Posted: Sun Jan 13, 2008 3:52 am
by Fredy
Dispage I was FTPing to the server to test.
I remuved the function mysql_prep and replace it with htmlenities.
Now it works fine and I hope htmlentities replacement.
Thanks for yor help Everah