.PhP issue - Puzzle pieces of code
I have been struggling to send HTML mail using my script with no success.
The issue is I CANNOT add an anchor tag "<a href=""></a>" in the $message. It gets through something like: "<a href=\"http://www.google.com\">Click Here</a>" - Notice the "\"
#puzzle piece 1
(taken from my simple script)
<?php
if (isset($_GET['email'])) {
$email = $_GET['email'];
$message = $_GET['message'];
$from = $_GET['from'];
$subject = $_GET['subject'];
mail( $email, $subject, $message, "From: $from" );
print "email was sent succesfully";
}
else {
?>
<form method="get" action="email.php">
To Email: <input name="email" type="text"><br>
From Email: <input name="from" type="text"><br>
Subject: <input name="subject" type="text"><br>
Message:
<textarea name="message" rows="10" cols="30"></textarea>
<input type="submit">
</form>
<?php
}
?>
Alright, now you might obviously see that I have NOT set the $headers correctly, like:
**#puzzle piece 2 **
(taken from http://us2.php.net/manual/en/function.mail.php)
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Furthermore.. someone suggested that I have to include in my form the following:
#puzzle piece 3
(taken from a friend)
ENCTYPE="multipart/form-data"
FINAL 100points question: How do I mix all of that coding and create the one script that will correctly interpret the HTML in it?
All I need is ONE ANCHOR TAB, thats all. Any help whatsoever is very appreciated, thanks in advance.
I don't really feel like disecting it for errors, here's a mail app of mine that works though:
<?php
$to = strip_tags($_POST['to']);
$subject = strip_tags($_POST['subject']);
$message = strip_tags($_POST['message']);
echo <<<HERE
<form method="post" name="form">To: <input type="text" name="to"><br>
Subject: <input type="text" name="subject"><br>
Message: <input type="text" name="message"><input type="submit" value="Submit">
</form>
HERE;
if ($_POST['to'] && $_POST['subject'] && $_POST['message'])
mail($to,$subject,$message);
else
die();
?>
R26 wrote: AldarHawk: Why POST instead of GET ?
slpctrl: Thanks for the script, but its not exactly what I need.. still you cannot include HTML in it.
Any other suggestion would be appreciated.
Oh ok I get it now and I believe it's probably going to be much more difficult than anything you could do, but I donno because I haven't sat down and written one so I could be wrong. I didn't understand what you meant there and thought you needed a simple mail script. And use POST for sure, not get. You should only use GET when simply retrieving data and not really doing much with it ( in a nutshell that's the best way I can explain it :right: ) you use POST for anything like storing data, email etc.
Edit: It's not that hard at all, you just have to append your additional headers:
$headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
To the header section for the MAIL function in PHP.
R26 wrote: I tried that.. but that would mean I would take off the "$from" in mail() and exhange it with $headers - right? (plus, declare them)
Didnt work. Or you meant in your script? Im a little confused here..
mail(to,subject,message,headers,parameters)
In the mail function, there's a section for headers. If you simply do:
$headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Add that into your PHP, and where the headers go in the mail function include $headers. Everything else is pretty self explanatory. And USE POST :p