Web Hosting Talk







View Full Version : PHP Mail Help


KieranT
11-26-2008, 07:02 PM
PHP Mail Help

Hi,
I'm learning PHP in spare time, and I'm currently attempting a mail script, as far as I can see everything is how it should be? anyway here is my code:
Code:
<html>
<body>
<form action="mailform.php" method="post">
Email To: <input type="text" name="email" />
Subject: <input type="text" name="subject" />
Message: <input type="text" name="message" />
<input type="submit" />
</body>
</html>
The above code is in email.php
Code:
<html>
<body>
<?php
$email = <?php echo $_POST["email"];
$subject = <?php echo $_POST["subject"];
$message = <?php echo $_POST["message"];
// Use wordwrap() if lines are longer than 70 characters
$email = wordwrap($email,70);
// Send email
mail($email,$subject,$message);
?>
</body>
</html>
The second is mailform.php
If you wish to check this code in action its located:
D3Clans.Com/Kieran/PHP/email.php
Any help me appreciated
Kier

etogre
11-26-2008, 07:04 PM
PHP Code:



$email = <?php echo $_POST["email"];$subject = <?php echo $_POST["subject"];$message = <?php echo $_POST["message"];




Should just be
PHP Code:



$email = $_POST["email"];$subject = $_POST["subject"];$message = $_POST["message"];




I would also throw an htmlentities() around the $_POST variables at the very least.





__________________

KieranT
11-26-2008, 07:19 PM
Ty works a treat

tws
11-26-2008, 07:26 PM
You're going to want to add session handling to ensure spammers don't find and use your script.

KieranT
11-26-2008, 07:28 PM
Yea, it was just something I wanted to test out and have a little fun with, thanks for advice if I further this script.
Kier

lidnoone
11-26-2008, 08:10 PM
I suggest you use phpmailer this is a neat class saving a lot of time especially when you send html mails.