/    Sign up×
Community /Pin to ProfileBookmark

PHP processing file input type

Hi, I’ve got a web-based form I’m trying to put together to send e-mails with attachments from a website, and I’m having trouble getting my process script to see the attachment’s variable.

Here’s the form:

[CODE]
<H2>Send e-mail mailout</H2>
<FORM ACTION=”mailout/processmailout2.php” METHOD=”POST” ENCTYPE=”multipart/form-data”>
<TABLE>
<TR><TD>Recipient mailing mist: </TD>
<TD><SELECT NAME=”recipientlist”>
<OPTION VALUE=”” SELECTED></OPTION>
<OPTION VALUE=”list1″>Vegenotes</OPTION>
<OPTION VALUE=”list2″>VegLink</OPTION>
<OPTION VALUE=”list3″>Vegetable Platter</OPTION>
<OPTION VALUE=”list4″>Good Fruit & Veg</OPTION>
<OPTION VALUE=”list5″>Diamond back Moth</OPTION>
</SELECT></TD></TR>

<TR><TD>Subject:</TD><TD><INPUT TYPE=”text” NAME=”subject” SIZE=”70″></TD></TR>

<TR><TD>Attachment:</TD><TD><INPUT TYPE=”file” NAME=”attchmnt” SIZE=”60″></TD></TR>
</TABLE>

Message:<BR>
<TEXTAREA NAME=”message” COLS=”80″ SIZE=”5″></TEXTAREA><BR>

<INPUT TYPE=”submit” VALUE=”Send”>
</FORM>
[/CODE]

processmailout.php is the script I’m using to handle the actual sending once the form is filled out, and this is it below.

[code=php]
<?php
//processcreate.php is the script responsible for processing the data from
//the createprofile.php form after it has been verified by the JS checker
//and then updates the database as appropriate.

require(“class.phpmailer.php”);

$mailer = new PHPMailer();
$mailer->From = “from@address”;
$mailer->FromName = “name”;
$mailer->Host = “our.host.com.au”;
$mailer->Mailer = “smtp”;
$mailer->Body = $message;
$mailer->Subject = $subject;
$mailer->Username = “user”;
$mailer->Password = “pass”;

if ($attchmnt != “”) {
if ($mailer->AddAttachment($attchmnt)) {
echo “attached”;
} else {
echo “failed: ” . $mailer->ErrorInfo.”<BR>”;
}
} else {
echo “no attachment!”;
}

$to = “[email protected]”;
$name = “Recipient name”;

$mailer->AddAddress($to,$name);
if (!($mailer->Send())) {
echo “Not sent for $name <$to><BR>”;
}
$mailer->ClearAddresses();
?>
[/code]

The output from this processmailout.php script is “no attachment!”, so I’m not too sure what’s goin wrong.

The file “class.mailer.php” is the PHPMailer script from [URL]http://phpmailer.sourceforge.net[/URL]

Anyone with any tips/suggestions would be greatly appreciated.

?

edit: Solved it by using $_FILES properly. My script to replace $_POST[‘blah’] with $blah, etc wasn’t set to handle the $_FILES array. :p

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @Chris_J_W spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...