/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] scrambled code

Hi,

I don’t know php just a bit of javascript. I have the code below which is part from a mail script:

[code=html]<html>
<head><title>PHP Mail Sender</title></head>
<body>
<?php

/* All form fields are automatically passed to the PHP script through the array $HTTP_POST_VARS. */
$email = $HTTP_POST_VARS[’email’];
$subject = $HTTP_POST_VARS[‘subject’];
$message = $HTTP_POST_VARS[‘message’];

/* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn’t empty. preg_match performs a regular expression match. It’s a very powerful PHP function to validate form fields and other strings – see PHP manual for details. */
if (!preg_match(“/w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*/”, $email)) {
echo “<h4>Invalid email address</h4>”;
echo “<a href=’javascript:history.back(1);’>Back</a>”;
} elseif ($subject == “”) {
echo “<h4>No subject</h4>”;
echo “<a href=’javascript:history.back(1);’>Back</a>”;
}

/* Sends the mail and outputs the “Thank you” string if the mail is successfully sent, or the error string otherwise. */
elseif (mail($email,$subject,$message)) {
echo “<h4>Thank you for sending email</h4>”;
} else {
echo “<h4>Can’t send email to $email</h4>”;
}
?>
</body>
</html> [/code]

The text sent is this:

[code=html]<img src=”http://fc06.deviantart.com/fs49/i/2009/159/3/2/Forgotten_Hope_by_silentfuneral.jpg”/>[/code]

and was received this:

[code=html]<img src=”http://fc06.deviantart.com/fs49/i/2009/159/3/2/Forgotten_Hope_by_silentfuneral.jpg”/> [/code]

My guess is that is scrambling the text sent in order to prevent html insertion.
So, my question is: it is true ?

Meanwhile I have found that the mail server is scrambling the html code. Is there any mail script that sends html ?

New edit:
I found out that I need these lines in the php file:

[code=html]// To send HTML mail, the Content-type header must be set
$headers = ‘MIME-Version: 1.0’ . “rn”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . “rn”;[/code]

but I don’t know how to handle it. Any suggestion ?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@Four_StaplesJun 08.2009 — Those slashes are being added in because your server has magic quotes enabled (applies addslashes() to all POST/GET/REQUEST variables). I recommend disabling it entirely as it's been deprecated, but you can reverse the process by simply using addslashes() on your POST variables before you mail().

[url=http://ca2.php.net/magic_quotes]PHP: Magic Quotes[/url]
Copy linkTweet thisAlerts:
@akkadIIauthorJun 08.2009 — Those slashes are being added in because your server has magic quotes enabled (applies addslashes() to all POST/GET/REQUEST variables). I recommend disabling it entirely as it's been deprecated, but you can reverse the process by simply using addslashes() on your POST variables before you mail().

[url=http://ca2.php.net/magic_quotes]PHP: Magic Quotes[/url][/QUOTE]



I think that you are right. It happen only at POST cases.

I can't change the server's config so I need to strip these quotes at runtime.

So in my code where should be placed that addslashes() ?
Copy linkTweet thisAlerts:
@ShortsJun 08.2009 — Around all the post variables, e.g.:

[code=php]
$email = stripslashes($HTTP_POST_VARS['email']);
[/code]
Copy linkTweet thisAlerts:
@akkadIIauthorJun 08.2009 — thanks both for help. Cheers
×

Success!

Help @akkadII spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...