Krijg iedere keer de "Failed to move file to /tmp/3ed3186da55a7462dffaeaec5f1449ac0227e16500mHVo "

Ik Neem aan dat me directory niet goed is waar ik het bestand tijdelijke wil opslaan.
Maar het is toch een temp file ?

Alvast bedankt voor de hulp.

Dit zijn de codes standaard PHPmailer scripts.


PHPMailerAutoload.php

<?php
/**
 * PHPMailer SPL autoloader.
 * PHP Version 5
 * @package PHPMailer
 * @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
 * @author Marcus Bointon (Synchro/coolbru) <[email protected]>
 * @author Jim Jagielski (jimjag) <[email protected]>
 * @author Andy Prevost (codeworxtech) <[email protected]>
 * @author Brent R. Matzelle (original founder)
 * @copyright 2012 - 2014 Marcus Bointon
 * @copyright 2010 - 2012 Jim Jagielski
 * @copyright 2004 - 2009 Andy Prevost
 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
 * @note This program is distributed in the hope that it will be useful - WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 */

/**
 * PHPMailer SPL autoloader.
 * @param string $classname The name of the class to load
 */
function PHPMailerAutoload($classname)
{
    //Can't use __DIR__ as it's only in PHP 5.3+
    $filename = dirname(__FILE__).DIRECTORY_SEPARATOR.'class.'.strtolower($classname).'.php';
    if (is_readable($filename)) {
        require $filename;
    }
}

if (version_compare(PHP_VERSION, '5.1.2', '>=')) {
    //SPL autoloading was introduced in PHP 5.1.2
    if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
        spl_autoload_register('PHPMailerAutoload', true, true);
    } else {
        spl_autoload_register('PHPMailerAutoload');
    }
} else {
    /**
     * Fall back to traditional autoload for old PHP versions
     * @param string $classname The name of the class to load
     */
    function __autoload($classname)
    {
        PHPMailerAutoload($classname);
    }
}

?>

En me mailpagina.
<?php
/**
 * PHPMailer simple file upload and send example
 */
$msg = '';
if (array_key_exists('userfile', $_FILES)) {
    // First handle the upload
    // Don't trust provided filename - same goes for MIME types
    // See http://php.net/manual/en/features.file-upload.php#114004 for more thorough upload validation
    $uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES['userfile']['name']));
    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
        // Upload handled successfully
        // Now create a message
        // This should be somewhere in your include_path
        require 'PHPMailerAutoload.php';
        $mail = new PHPMailer;
        $mail->setFrom('[email protected]', 'First Last');
        $mail->addAddress('[email protected]', 'John Doe');
        $mail->Subject = 'Verkoopmelding'.$Verkoopbureau;
        $mail->msgHTML("My message body");
        // Attach the uploaded file
        $mail->addAttachment($uploadfile, 'My uploaded file');
        if (!$mail->send()) {
            $msg = "Mailer Error: " . $mail->ErrorInfo;
        } else {
            $msg = "Message sent!";
        }
    } else {
        $msg = 'Failed to move file to ' . $uploadfile;
    }
}
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>PHPMailer Upload</title>
</head>
<body>
<?php if (empty($msg)) { ?>
    <form method="post"  enctype="multipart/form-data">
        <input type="hidden" name="MAX_FILE_SIZE" value="1000000"> Send this file: <input name="userfile" type="file">
        <input type="submit" value="Send File">
    </form>
<?php } else {
    echo $msg;
} ?>
</body>
</html>


[size=xsmall]Toevoeging op 29/12/2014 07:52:53:[/size]

p.s wat zijn de code Tags om html in vensters te weergeven op dit form ?

Beste Jordy,

Iedereen probeert je goed te helpen en dat is prima maar als ik dit even vanaf een kleine afstand bekijk dan gaat er iets in de basis fout. Je wilt namelijk een script maken die twee dingen doet:

a) fileupload form met afhandeling
b) genereren en verzenden email

De fout die je maakt is dat je zevenmijlslaarzen aantrekt en van start in een stap naar de finish wilt. Dat doe je dus door een kant en klaar script te kopiëren en dan hoop je dat dit werkt.

Ik zou nu tegen je willen zeggen: ga eens terug naar start en begin met de file upload en haal die hele PHPMailer er eens uit. Zorg dat het perfect werkt en dat je begrijpt waarom het werkt. Hierbij dien je er voor te zorgen dat de afhandeling (het valideren en kopiëren van het bestand en opslaan van gegevens in de database) door een aparte functie of een groep van functies gebeurd. Vergeet daarnaast ook de beveiliging niet. een fileupload is in de basis een gapend gat in je firewall. Maak een whitelist van extensies die je accepteert maar vooral ook van de MIME-TYPES die je accepteert. Internet staan vol interessant leesvoer over dit onderwerp.

Waarom functies?
- Omdat je dan je code kunt scheiden.
- Omdat je code kunt hergebruiken in hetzelfde project maar ook in andere projecten
- Omdat je code veel beter leesbaar wordt
- Omdat je overlapping van variabelen uitsluit

Maak daarna een nieuw project die een functie aanroept en een email in elkaar zet en met PHPMailer verstuurd.

Pas daarna ga je de code samenvoegen.
nog wat gepuzzeld en
alles werkt ik wil jullie graag bedanken voor alle moeite en tijd.

er zat ook een fout in me class.phpmailer

Dank u

wat is toch die "me"? is het niet php wat je gebruikt?

of is "me" een of andere afkorting of begrip dat ik niet ken?
me => mijn
- SanThe - op 30/12/2014 14:34:28

Aar bedoelt dit waarschijnlijk:
<?php
echo "<pre>".print_r($_FILES, true)."</pre>";
?>

oeps...
Klopt, was de rest vergeten...

Reageren