I have seen this is a common question but through searching I haven't found the answer I need. I have used PHP code to create a mailer with attachments that are located on my server.
My site has a CRUD system and the read.php file displays various elements of an uploaded file. I also have a form on this page which allows the user to enter and email address and message to send on the said file.
My form code is:-
<form class="form-horizontal" action="mailer.php" method="post">
<div class="form-group">
<label class="col-sm-2">Email Address</label>
<div class="col-sm-4">
<input name="doc_email" type="text" placeholder="Enter Email Address to" class="form-control" >
</div>
</div>
<div class="form-group">
<label class="col-sm-2">Message</label>
<div class="col-sm-4">
<input name="doc_message" type="text" placeholder="Enter a message (not mandatory)" class="form-control" >
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-success">Send Email</button>
</div>
</form>
And my mailer.php code is currently;-
<?php
if (isset($_POST['submit']))
{
$file_name = $_POST['file_name'];
$doc_email = $_POST['doc_email'];
$doc_message = $_POST['doc_message'];
require_once('class.phpmailer.php');
$email = new PHPMailer();
$email->From = 'you@example.com';
$email->FromName = 'Your Name';
$email->Subject = 'Message Subject';
$email->Body = $doc_message;
$email->AddAddress = $doc_email;
$path_file_to_attach = '/documents/uploads/';
$file_to_attach = $file_name;
$email->AddAttachment( $path_file_to_attach , $file_to_attach );
return $email->Send();
//redirect user after success
header("Location: index.php");
}
?>
The class.phpmailer.php file is within the same directory (/documents) as the read.php/mailer.php, all I get is a blank screen with no email or errors.
The folder with the files is located in a sub folder called 'uploads'... documents/uploads/
Any help as always is greatly appreciated.