Hi All
I am using PHPMailer to send information from a web form on my company website. The form sends; name, subject, browse for file and message. The user will input these details and then hit send which will invoke phpmailer.inc.php and do all the sending and send a automated response to the sender. I've tested this without the attachment option and all is sending fine.
However when I add the AddAttachment and hit send I get this;
Mailer Error
Description:
Could not find file on filesystem
I don't want to upload this file to a database or anything like that, I just want it to attach to an email and send a copy to mailbox within our company which receives our students work.
I think the thing I'm confused about is that I'm not sure what to put in the argument of the AddAttachment; AddAttachment(string path <-What's supposed to go in here, what does it mean string path?). I thought it would be $_POST['name of button from web form'] so that it could get the file from the web form and then pass this to phpmailer.inc.php?
The files that will be being uploaded by our students could be .doc .docx .pdf .ppt .xls .zip.
Below is the Web form code and the form that interacts with this and feeds phpmailer.inc.php.
<form action="submitworkNew.php" method="post" enctype="multipart/form-data" name="form1" class="content" id="form1">
<label>
1. Your Name (please select)<br />
<select name="name3" id="name3">
<option>example@nothing.com</option>
</select>
</label>
<h6>
<label> </label>
<label>2. <span id="sprytextfield3">Subject<br />
<input type="text" name="subject" id="subject" />
</span><span><span class="textfieldRequiredMsg">A value is required.</span></span><br />
<br />
3. Browse for file<br />
<input type="file" name="file" id="file" />
<br />
</label>
</h6>
<h6>4. <span id="sprytextarea2">
<label>Message (optional)<br />
<textarea name="message2" id="message2" cols="30" rows="5"></textarea>
</label>
</span> <span id="sprytextarea1"><br />
</span></h6>
<p>
<input type="submit" name="submit" id="submit" value="Submit" />
<input type="submit" name="reset" id="reset" value="Reset" />
</p>
</form>
submitworkNew.php
<?php
require_once 'phpmailer.inc.php';
//Send Email
$mail = new phpmailer();
$mail->From = $_POST['name3'];
$mail->Subject = $_POST['subject'];
$body = $_POST['message2'];
$mail->Body = $body;
$mail->AddAddress('something.com');
$mail->AddAttachment($_POST['file']/'file.doc'); <-- Confused about what to put here
//If OK send acknowledgement email to candidate
if(!$mail->Send()){
$toTwo = 'somehitng.com'; //$_POST['name3']
$subjectTwo = '';
$emailFrom = 'Acknowledgement of work submission DO-NOT-REPLY';
$messageTwo = '
Hi
Thank you for your work submission. Advisors endeavour to respond to your email within 10 working days, however you will be notified if there are any exceptions to this standard. If you have any other queries that need urgent attention please call the office on **.
Kind regards,
';
$mailheaders = 'PLEASE DO NOT REPLY TO THIS MESSAGE';
mail($toTwo, $emailFrom, $subjectTwo, $messageTwo, $mailheaders);
echo "<p>mail has been sent!</p>";
echo 'Mail sent successfully';
}
else
{
echo 'Mail sending failed';
}
?>
Help would be MUCHLY appreciated, I'm sure its a quick fix, just need to put the right details for AddAttachment. I've been scratching my head for 2 days on this now and its really getting to me!
HELP!
Thanks for any help in advance,
James