I created simple code to send e-mails via contact form.
I would like to add button to attach image file and as attachment send with e-mail (use contact form).
Button
<input type="file" id="uploadfile" name="uploadfile" accept="image/*" placeholder="">
PHP Code
header("content-type: application/json; charset=utf-8");
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "to@namedomain.com";
$subject = "Title";
if($name && $email && $message){
$mailheader = "MIME-Version: 1.0\r\n";
$mailheader .= "Content-type: text/plain; charset=utf-8\r\n";
$mailheader .= "From: ".$email." \n\r";
$formcontent = "Subject: $name \n\n $message \n" ;
if(mail($to,$subject,$formcontent,$mailheader)){
$json=array("status"=>1,"msg"=>"<p class='status_ok'>Success.</p>");
}
else{
$json=array("status"=>0,"msg"=>"<p class='status_err'>Fail.</p>");
}
}
else{
$json=array("status"=>0,"msg"=>"<p class='status_err'>All fields required.</p>");
}
echo json_encode($json);
exit;
I was trying to look for that but no success. I would like to get something what will be work with my case. I found something about PHPMailer but I don't understand how I can use it with my case so I would like to stay with my structure.