PHPMailer attachment argument

the mail() function

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 7
Joined: Fri Jun 03, 2011 7:15 am

Tue Jun 21, 2011 4:53 am

Hello everyone,
I'm a noob and I'm trying to send an attachment via an html form using phpmailer.

I've used the argument $mail->AddAttachment($_FILES['uploaded_file']['name']); in the script that instantiates the class but it doesn't send the attachment.
I've been told that I must write code that moves the attachment from the tmp folder to another folder before it will send. Is that correct? Is it possible to send the attachment directly from the tmp folder?

I'd rather not have to move the file to another folder and then have to constantly delete them.

Below is the html form and the script that feeds the class.phpmailer.php

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "">

<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>Quote Blaster</title></head><body>
<div style="text-align: center;"><br>
<table style="text-align: left; background-color: rgb(255, 204, 153); margin-left: auto; margin-right: auto; height: 400px; width: 500px;" border="1" cellpadding="2" cellspacing="2">
<td style="vertical-align: middle; width: 490px; text-align: center;">
<b>QUOTE BLASTER</b><br>
Fill out the information below and press send to email the quote.<br>
<form action="mail.php" enctype="multipart/form-data" method="post">
<span style="font-weight: bold; color: rgb(0, 0, 70);">Choose the
Sales Rep:
<select size="1" name="rep"><option selected="selected">CHOOSE-REP</option>
<option value=" Jo joschmoe">Jo Schmoe</option>


<span style="font-weight: bold; color: rgb(0, 0, 70);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Quote #: <input name="quote" type="text"><br>
<span style="font-weight: bold; color: rgb(0, 0, 70);">Clients
email: <input name="email" type="text"><br>
<br>&nbsp; Clients
<span style="font-weight: bold; color: rgb(0, 0, 70);">First
name: <input name="firstname" type="text"><br>
<span style="font-weight: bold; color: rgb(0, 0, 70);">Clients Last
name: <input name="lastname" type="text"><br>
<input name="MAX_FILE_SIZE" value="30000" type="hidden">
<span style="font-weight: bold; color: rgb(0, 0, 70);"> <label for="uploaded_file">Select A File To Upload:</label> <input size="25" name="uploaded_file" type="file"><br><br>
</span><input value="SEND" input="" type="submit"> </span></span></span></span></span></form>



$mail = new PHPMailer();

//splits the values in rep
$pizza = $_POST['rep'];
$repinfo = explode(" ", $pizza);

//uses mail

$mail->From = '';


$mail->AddAttachment($_FILES['uploaded_file']['name']); //<--- I thought this would work but it doesnt


$mail->Subject = "myquote # " . $_POST[quote];
$mail->Body =
//begin of HTML message
<left> Hello $_POST[firstname],<br>
Your printing quotation from <span style="font-weight: bold;">us g</span> is complete. For your reference your project is:
Quote Number $_POST[quote].<br>
<!--post reps full name all lower case here in the href (replacing rodsmith)-->
If you have any questions, need samples or any further information,
please visit my Bio page just <a
href="$repinfo[2]/$_POS ... te]">click
In this email, our custom quotation is attached in PDF format.
Thank you $_POST[firstname], I hope we can work together on this project.<br>
<!--post reps first name here-->
$repinfo[1] <br>
Account Executive<br>
<!--post reps email address here-->
<a href="mailto:$repinfo[0]">$repinfo[0]</a><br>

//end of html message
//$mail->WordWrap = 80;

if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';

Any help someone could give me would be GREATLY appreciated.

Thanks in advance,

Last edited by JRick on Wed Jun 22, 2011 6:17 pm, edited 1 time in total.

Post Reply