leeboycymru
Programmer
I had a simple form sending an email with the users details. I want to now add a file attachment, and have looked in google and there seems to be answers, but they are very difficult to follow.
This is my code:
and here's the php, can somebody help me fill in the blanks please.
This is my code:
Code:
<form method="post" action="sendmail.php">
Name: <br/>
<input name="name" type="text" id="Contact" size="30" />
<br/>
<br/>
Company Name: <br/>
<input name="company" type="text" id="Contact1" size="30" />
<br/>
<br/>
Telephone: <br/>
<input name="telephone" type="text" id="Contact2" size="30" />
<br/>
<br/>
Email: <br/>
<input name="email" type="text" id="Contact3" size="30" />
<br/>
<br/>
Message:<br/>
<textarea id="Contact4" name="message" rows="10" cols="40"></textarea>
<br/>
<br/>
Attachment:<br/>
<input type="file" name="FileAttachment" />
<br/>
<br/>
<input id="SubContact" type="submit" />
</form>
and here's the php, can somebody help me fill in the blanks please.
Code:
<?
$name = $_REQUEST['name'];
$company = $_REQUEST['company'];
$telephone = $_REQUEST['telephone'];
$email = $_REQUEST['email'];
$message = $_REQUEST['message'];
$attachment = $_FILES['FileAttachment'];
$message = "Message submitted at ".date("d/m/y - h:m")."\r\n
By: $name\r\n
Company Name: $company\r\n
Phone: $telephone\r\n
Message: \r\n $message";
if (empty($_REQUEST['email']) || empty($_REQUEST['name']) || empty($_REQUEST['message']) || empty($_REQUEST['company'])) {
?>
<html>
<head>
<title>Email Error</title>
</head>
<body>
<h1>Email Error</h1>
<p>
Sorry, it appears that you have forgotten to enter either your name, your email address or your message.</p>
<p>Please press the <strong>BACK</strong> button in your browser and try again.</p>
</body>
</html>
<?
}
else {
mail("info@hobbsvalve.co.uk", "Message from website",
$message, "From: $name <$email>");
header ("Location: [URL unfurl="true"]http://www.hobbsvalve.co.uk/thankyou.htm");[/URL]
}
?>