0

I currently have a form where the user can complete textfields and textareas to fill in an online form once filled out and submit is pressed it is sent to my email.

Im having issues getting images to attach however, so that they come through as an attachment in the email. I have changed the form in the html by adding enctype="multipart/form-data":

<form id="contact-form" form name="contactform" method="post" enctype="multipart/form-data" action="send_list_email.php">

And:

<input type="file" name="fileToUpload" id="fileToUpload">

As for the php I currently have this for my text form:

<?php

if(isset($_POST['email'])) {

$email_to = "info@xxx.co.uk";

$email_subject = 'Thank you for filling in the form!';

$email_from = "info@xxx.co.uk"; 

function died($error) {

include("sorry.htm");
("Location:sorry.htm");     
die();
}    

if(!isset($_POST['formtext']) }

$form = $_POST['formtext'];

$error_message = "";

$email_message .= " ".clean_string($formtext)."\n"; 

// create email headers

$headers = 'From: '.$email_from."\r\n".

'Reply-To: '.$email_from."\r\n" .

'X-Mailer: PHP/' . phpversion();

@mail($email_to, $email_subject, $email_message, $headers);  

@mail($email_customer, $email_subject, $email_message, $headers); 

?>

<?php
include("thanks.htm");
 ("Location:thanks.htm");
?> 

<?php

}

?>  

I have tried a few different ways but can't get the image to store as an attachment and be sent with the form.

Any help would be appreciated!

Bethfiander
  • 167
  • 1
  • 2
  • 14
  • are you using PHP mailer script ? to send an email if not then go for it **PHP Mailer** having functionality – Soni Vimalkumar Nov 09 '16 at 13:13
  • Please please use an existing library such as PHPMailer for this kind of stuff. Attachments in e-mails are not the most obvious or simple of tasks to do from scratch reliably. – Jonnix Nov 09 '16 at 13:13

0 Answers0