php - Send email with attachment via PHPMailer -


i'm preparing create form page website require many fields user fill out , sent specified email.

so far i've created dummy php email page gets message, 1 attachment, , recipient email address using google's smtp.

here's code uploadtest.html:

<body>  <h1>test upload</h1>  <form action="email.php" method="get"> message: <input type="text" name="message"> email: <input type="text" name="email"><br> attach file: <input type="file" name="file" id="file"> <input type="submit"> </form>   </body> 

uploadtest.html user see

here's code email.php:

<?php     require("class.phpmailer.php");      $mail = new phpmailer();      $recipiant = $_get["email"];     $message = $_get["message"];      $mail->issmtp();  // telling class use smtp     $mail->smtpauth   = true; // smtp authentication     $mail->host       = "smtp.gmail.com"; // smtp server     $mail->port       = 465; // smtp port     $mail->smtpsecure = 'ssl';     $mail->username   = "xxxxx@gmail.com"; // smtp account username     $mail->password   = "xxxxxxxx";        // smtp account password       $mail->addattachment($_files['tmp_name']); //****here's main problem!!!       $mail->setfrom('cinicraftmatt@gmail.com', 'cinicraft.com'); //     $mail->addreplyto('cinicraftmatt@gmail.com', 'dom'); // reply      $mail->addaddress($recipiant, 'dominik andrzejczuk'); // recipient email      $mail->subject    = "first smtp message"; // email subject     $mail->body       = $message;          if(!$mail->send()) {       echo 'message not sent.';       echo 'mailer error: ' . $mail->errorinfo;     } else {       echo 'message has been sent.';     } ?> 

so can tell here, phpmailer's addattachment() method takes parameter url of file directory want attached. , main problem is.

what name of variable location of file (dir/upload.jpg) i've uploaded use parameter in addattachment() method?

no, doesn't take urls, or directories. takes direct path file.

e.g.

$mailer->addattachment(     '/path/to/file/on/your/server.txt',     'name_of_file_in_email',     'base64',     'mime/type' ); 

the path self-explanatory. name_of_file_in_email allows "rename" file, might loaded file named "foo.exe" on server, can appear "bar.jpg" in email client receives.

your problem you're trying attach uploaded file, using wrong source. should be

<input type="file" name="thefile" />                          ^^^^^^^ $_files['thefile']['tmp_name']          ^^^^^^^ 

note field name relationship $_files.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -