Hi, I've bought webspace with a company and they sent me their own php script for email (see below). They don't accept formail or cgi for security reasons. They sent me this page below with instructions to paste it into a html editor and save as mail.php doc and change certain fields to make it work. If I try that, its a mess.
Also, the document is a html form AND php script already. How can the two be separated - obviously I want to put the form into my own html page. I've tried to paste the form into my web page and upload the rest as a php file but it doesn't work like that.
Any basic ideas on how this should be done? Does this script look dodgy to anyone else?
HTML Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Using PHP mail()</title>
</head>
<body>
<?php
// ==================================
// Change these variables accordingly
// ==================================
$fromName = "Your name here"; // from name
$from = "Message from here (email address)"; // from address
$reply = "Reply to address (email address)"; // reply-to address
// ==================================
if($_POST['submit'] && $_POST['submit'] == "sendmail")
{
// ==================================
// Do not change these variables
// ==================================
$to = $_POST['to'];
$sub = $_POST['sub'];
$mailbody = $_POST['body'];
// ==================================
// Check email address is valid
// ==================================
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$", $to)) {
echo "<p><b>Not a valid email address, please go back and try again</b></p>";
exit;
}
// ==================================
// Send the email
// ==================================
$mailheaders .= "Content-Type: text/plain; charset=charset=iso-8859-1\n";
$mailheaders .= "From: " . $fromName . "<".$from.">\n";
$mailheaders .= "Reply-To: ".$reply.""."\n";
if(mail($to,$sub,$mailbody,$mailheaders))
echo "<p><b>Message Sent</b>";
else
echo "<p><b>Unexpected Error! Message Not Sent</b>";
}
// ==================================
// Show the HTML form
// ==================================
?>
<p><b>Send a message using PHP mail()</b></p>
<form action="<?php echo $PHP_SELF; ?>" method="post">
To:<br>
<input type="text" name="to" size="40"><br>
Subject:<br>
<input type="text" name="sub" size="40"><br>
Message:<br>
<textarea name="body" cols="50" rows="10">
Enter your message here
</textarea><br><br>
<input type="submit" name="submit" value="sendmail">
</form>
</body>
</html>
Last edited by Dan Bowley; 06-24-2005 at 09:24 AM..
Reason: better title
|