Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

.PhP issue - Puzzle pieces of code


ghost's Avatar
0 0

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)

&lt;?php
if (isset($_GET[&#39;email&#39;])) {
$email = $_GET[&#39;email&#39;];
$message = $_GET[&#39;message&#39;];
$from = $_GET[&#39;from&#39;];
$subject = $_GET[&#39;subject&#39;];
mail( $email, $subject, $message, &quot;From: $from&quot; );
print &quot;email was sent succesfully&quot;;
}
else {
?&gt;
&lt;form method=&quot;get&quot; action=&quot;email.php&quot;&gt;
To Email: &lt;input name=&quot;email&quot; type=&quot;text&quot;&gt;&lt;br&gt;
From Email: &lt;input name=&quot;from&quot; type=&quot;text&quot;&gt;&lt;br&gt;
Subject: &lt;input name=&quot;subject&quot; type=&quot;text&quot;&gt;&lt;br&gt;
Message:
&lt;textarea name=&quot;message&quot; rows=&quot;10&quot; cols=&quot;30&quot;&gt;&lt;/textarea&gt;
&lt;input type=&quot;submit&quot;&gt;
&lt;/form&gt;
&lt;?php
}
?&gt;

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  = &#39;MIME-Version: 1.0&#39; . &quot;&#92;r&#92;n&quot;;
$headers .= &#39;Content-type: text/html; charset=iso-8859-1&#39; . &quot;&#92;r&#92;n&quot;;

Furthermore.. someone suggested that I have to include in my form the following:

#puzzle piece 3

(taken from a friend)

ENCTYPE=&quot;multipart/form-data&quot;

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.


AldarHawk's Avatar
The Manager
0 0

PM Me. I have a few PHP mail apps ;)

I would suggest using POST instead of GET…But that is just me.


ghost's Avatar
0 0

I don't really feel like disecting it for errors, here's a mail app of mine that works though:

&lt;?php
$to = strip_tags($_POST[&#39;to&#39;]);
$subject = strip_tags($_POST[&#39;subject&#39;]);
$message = strip_tags($_POST[&#39;message&#39;]);
echo &lt;&lt;&lt;HERE
&lt;form method=&quot;post&quot; name=&quot;form&quot;&gt;To: &lt;input type=&quot;text&quot; name=&quot;to&quot;&gt;&lt;br&gt;
Subject: &lt;input type=&quot;text&quot; name=&quot;subject&quot;&gt;&lt;br&gt;
Message: &lt;input type=&quot;text&quot; name=&quot;message&quot;&gt;&lt;input type=&quot;submit&quot; value=&quot;Submit&quot;&gt;
&lt;/form&gt;
HERE;
if ($_POST[&#39;to&#39;] && $_POST[&#39;subject&#39;] && $_POST[&#39;message&#39;])
mail($to,$subject,$message);
else
die();
?&gt;

ghost's Avatar
0 0

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.


ghost's Avatar
0 0

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.


ghost's Avatar
0 0

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..


ghost's Avatar
0 0

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


ghost's Avatar
0 0

You should also declare your other variables as headers too and include them aswell.


ghost's Avatar
0 0

Hm, Okay I will try although I tried over and over again. Thanks for your time and patience.


ghost's Avatar
0 0

R26 wrote: OK, thanks for the advice .. Its clearer now .. Only one thingy - How am I going to specify the $from if I take it off mail() ? I wish to enter that also..

Oh, I think I gottit so I include the $from in the headers, right?

Yup