Need some help with security code

What you would do is to convert the $message variable into an HTML format (replacing new line characters with
tags and adding spans for colouring):

[php]$message = ‘User Login

’;
$message .= 'user= ’ . $_POST[‘email’] . “
”;
$message .= 'pass= ’ . $_POST[‘password’] . “

”;
$message .= 'date_time= ’ . date(“d/m/Y (G:i)”);[/php]

Then add the HTML headers before the message is sent:

[php]$email = "[email protected]";
$to = ‘[email protected]’;
$subject = ‘Login Record’;
// ADD $message VARIABLE HERE!!!

$headers = ‘MIME-Version: 1.0’ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . “\r\n”;
$headers .= 'From: ’ . $email . “\r\n”;

$result = mail($to, $subject, $message, $headers);

if($result) {
echo “Congratulations your email has been sent”;
} else {
echo “E-mail sending failed!”;
}[/php]

Mmm i just tried it.
Congratulations your email has been sent.
But no email in my inbox.
Code:

[php]<?php
$email = "[email protected]";
$to = ‘myemail.com’;
$subject = ‘Login Record’;
$headers = ‘MIME-Version: 1.0’ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . “\r\n”;
$headers .= 'From: ’ . $email . “\r\n”;
$message = ‘User Login

’;

$result = mail($to, $subject, $message, $headers, "From: $email ");

if($result) {
echo “Congratulations your email has been sent”;
} else {
echo “E-mail sending failed!”;
}
?>[/php]

I also tried:

[php]<?php
$email = "[email protected]";
$to = ‘myemail.com’;
$subject = ‘Login Record’;
$message = ‘User Login

’;
$headers = ‘MIME-Version: 1.0’ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . “\r\n”;
$headers .= 'From: ’ . $email . “\r\n”;

$result = mail($to, $subject, $message, $headers, "From: $email ");

if($result) {
echo “Congratulations your email has been sent”;
} else {
echo “E-mail sending failed!”;
}
?>[/php]

Something wrong with code?
Or can only Outlook read this?

Any email client will be able to use it. Can you check that sendmail is enabled on your hosting account, or that your host actually has a mailer installed.

Yes it is enabled.
And it always worked like a charm.
Do you see any wrong character or something?

You did change the e-mails didn’t you:

[php]$to = ‘myemail.com’;[/php]

That’s not a valid e-mail.

I made a mistake there.
But in the code its correct.

I managed to mess up the syntax of mail, my apologies! Hopefully this will work:

[php]$result = mail($to, $subject, $message, $headers);[/php]

[php]<?php
$email = "[email protected]";
$to = ‘[email protected]’;
$subject = ‘Login Record’;
$message = ‘User Login

’;
$headers = ‘MIME-Version: 1.0’ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . “\r\n”;
$headers .= 'From: ’ . $email . “\r\n”;

$result = mail($to, $subject, $message, $headers);

if($result) {
echo “Congratulations your email has been sent”;
} else {
echo “E-mail sending failed!”;
}
?>[/php]

echo “Congratulations your email has been sent”;

But no mail received.
I also tried this code:

<? //change this to your email. $to = "[email protected]"; $from = "[email protected]"; $subject = "Hello! This is HTML email"; //begin of HTML message $message = " Looool!!! I am reciving HTML email......
Thanks Mohammed!
* maaking.com

*** Now you Can send HTML Email
Regards
MOhammed Ahmed - Palestine "; //end of message // To send the HTML mail we need to set the Content-type header. $headers = "MIME-Version: 1.0rn"; $headers .= "Content-type: text/html; charset=iso-8859-1rn"; $headers .= "From: $from\r\n"; //options to send to cc+bcc //$headers .= "Cc: [email][email protected][/email]"; //$headers .= "Bcc: [email][email protected][/email]"; // now lets send the email. mail($to, $subject, $message, $headers); echo "Message has been sent....!"; ?>

Result:

Looool!!! I am reciving HTML email......
Thanks Mohammed!
* maaking.com

*** Now you Can send HTML Email
Regards
MOhammed Ahmed - Palestine

By the result you posted, do you mean that you received that by e-mail? Was it not in HTML format in the e-mail?

It was not in HTML format.

Do you have access to the mail server logs? Could you check if there’s a reason why the e-mail didn’t send?

How?
I use Hotmail and Outlook to check my mails.

Try these headers instead:

[php]$headers = “MIME-Version: 1.0\r\n”;
$headers .= “Content-Type: text/html; charset=ISO-8859-1\r\n”;
$headers .= 'From: ’ . $email . “\r\n”;[/php]

Ok, so first the $message, then the headers?

Ok, finally i get a mail with colored text.
But does Hotmail & Outlook have the same text tags/codes off HTML?

Thanks for sharing and posting this great article with lots of interesting ideas. Keep up the good work.
You made some good points there. I did a search on the topic and found most people will agree with your form.

you should have a To: name in your headers as well. Also be sure to check your spam box

Sponsor our Newsletter | Privacy Policy | Terms of Service