1

I'm attempting to create a form that sends an email with user populated data. So far everything send correctly however the attachment is never included in the email sent. Any help would be appreciated.

HTML form asking user for data. "Mailerindex.html"

<html>
<head>
<link rel ="stylesheet" type = "text/css" href = "style.css" />
</head>
 <div class="form-style-8">

<body>
<form action= "PHPMailer.php" method ="POST" id="from" 
enctype="multipart/form-data"> 

 <input type="text" name="fname" placeholder="Your Name"/> 
 <input type="number" name="phoneNum" placeholder="Phone Number"/>
 <input type="email" name="email" placeholder="Email Address"/>
 <input type="text" name="desc" placeholder="Leave Description"/>
 <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
 <input type="file" name="file" placeholder="attachment" />

<input type="submit" value="submit" />

</form>

</div>
</body>
</html>

PHP script. "PHPMailer.php"

 <?php
    require 'PHPMailer-master/PHPMailerAutoload.php';
    require 'PHPMailer-master/class.phpmailer.php';
    $mail = new PHPMailer;
    $mail->isSMTP();                                     
    $mail->Host = 'smtp.xxxxxxxx.edu';  
    $mail->SMTPAuth = false;                              
    $mail->Username = '';                
    $mail->Password = '';                          
    $mail->SMTPSecure = 'TLS';                           
    $mail->Port = 25;                                    
    $mail->setFrom('xxxxxxxx@gmail.com', 'Mailer');
    $mail->addAddress('xxxxxxxxx@vt.edu', 'Joe User');   


    $mail->isHTML(true);                              
    $fnew =$_POST["fname"];
    $phone =$_POST["phoneNum"];
    $newEmail =$_POST["email"];
    $newDesc =$_POST["desc"];

    $file_to_attach = $_FILES['file']['tmp_name'];
    $filename=$_FILES['file']['name'];
    $mail->AddAttachment( $file_to_attach , $filename );



    $message = implode(' ', array($fnew,$phone,$newEmail,$newDesc)); 



$mail->Subject = 'Auto Email';
$mail->Body    = $message;


if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}
Ben
  • 11
  • 1
  • Possible duplicate https://stackoverflow.com/questions/23517106/uploading-an-image-from-contact-form-and-send-as-email-attachement – Muhammad Usman Jun 22 '17 at 19:10
  • https://stackoverflow.com/questions/38045547/how-to-get-php-mail-to-send-user-uploaded-image-to-my-email-address – Muhammad Usman Jun 22 '17 at 19:11
  • A shot in the dark here: you could try using [the example provided with PHPMailer](https://github.com/PHPMailer/PHPMailer/blob/master/examples/send_file_upload.phps) that does exactly what you're looking for, except without the security holes. – Synchro Jun 22 '17 at 19:13
  • Possible duplicate of [send attachment from form with phpmailer not working](https://stackoverflow.com/questions/28233901/send-attachment-from-form-with-phpmailer-not-working) – Synchro Jun 22 '17 at 19:14

0 Answers0