troubleshooting Question

Add attachment to form sent

Avatar of rhandalthor
rhandalthorFlag for Russian Federation asked on
PHPEmail Servers
20 Comments3 Solutions475 ViewsLast Modified:
I have a form and a handle form (send.php) to send form data + a file to an e-mail address. Emailing the general data and entering the CAPTCHA code works well, but I need PHP code to check for certain file types and add certain types of files to the email. I do not have PEAR at my disposal. Can someone help me editing this send.php that handles the form data so I can send attached files too?
$to      = '';
$subject = 'Rental Request';
$name    =  $_POST['name'];
$company =  $_POST['company'];
$email   =  $_POST['email'];
$url     =  $_POST['url'];
$contact =  $_POST['contact'];
$total_pages = $_POST['xpages'];
$headers = 'From:' . "\r\n" .
    'Reply-To:' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
$body  =  "From: $name\n Company: $company\n E-Mail: $email\n URL: $url\n Contact:\n $contact"; 
if( isset($_POST['submit'])) {
   if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) {
                // Insert you code for processing the form here, e.g emailing the submission, entering it into a database.
        mail($to, $subject, $body, $headers); 
                echo 'Thank you. Your message said "'.$_POST['xpages'].'"';
   } else {
                // Insert your code for showing an error message here
                echo 'Sorry, you have provided an invalid security code';
} else {
	<form action="/.send.php" method="post">
		<label for="name">Name: </label><input type="text" name="name" id="name" /><br />
		<label for="email">Email: </label><input type="text" name="email" id="email" /><br />
		<label for="message">Message: </label><textarea rows="5" cols="30" name="message" id="message"></textarea><br />
		<img src="./captcha/CaptchaSecurityImages.php?width=100&height=40&characters=5" /><br />
		<label for="security_code">Security Code: </label><input id="security_code" name="security_code" type="text" /><br />
		<input type="submit" name="submit" value="Submit" />

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 3 Answers and 20 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 20 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros