Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

PHPMailer attachment argument

the mail() function

Moderators: macek, egami, gesf

PHPMailer attachment argument

Postby JRick » 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" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>





<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>Quote Blaster</title></head><body>
<div style="text-align: center;"><br>
<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">
<tbody>
<tr>
<td style="vertical-align: middle; width: 490px; text-align: center;">
<br>
<b>QUOTE BLASTER</b><br>
<br>
Fill out the information below and press send to email the quote.<br>
<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="somebody@nobody.com Jo joschmoe">Jo Schmoe</option>

</select>


<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>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<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>
<br>&nbsp;&nbsp;
<span style="font-weight: bold; color: rgb(0, 0, 70);">Clients Last
name: <input name="lastname" type="text"><br>
<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>
<br>
</span><input value="SEND" input="" type="submit"> </span></span></span></span></span></form>
<br>
</td>
</tr>
</tbody>
</table>
<br>
</div>



</body></html>
_______________________________


<?php
require("class.phpmailer.php");

$mail = new PHPMailer();

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

//uses mail

$mail->From = 'me@myplace.com';
$mail->AddAddress("$email");

//$mail->addBCC("$test");


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

$mail->IsHTML(true);

$mail->Subject = "myquote # " . $_POST[quote];
$mail->Body =
//begin of HTML message
<<<EOF
<html>
<left> Hello $_POST[firstname],<br>
<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>
<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="http://www.mysite.com/$repinfo[2]/$_POST[firstname].$_POST[lastname].$_POST[quote]">click
here</a>.<br>
<br>
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>
<br>
<!--post reps first name here-->
$repinfo[1] <br>
Account Executive<br>
<br>
<!--post reps email address here-->
<a href="mailto:$repinfo[0]">$repinfo[0]</a><br>

</html>
EOF;
//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,

John
Last edited by JRick on Wed Jun 22, 2011 6:17 pm, edited 1 time in total.
JRick
New php-forum User
New php-forum User
 
Posts: 7
Joined: Fri Jun 03, 2011 7:15 am

Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.