PHPMailer User Attachments

别说谁变了你拦得住时间么 提交于 2020-01-11 12:29:08

问题


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';
}

来源:https://stackoverflow.com/questions/44707373/phpmailer-user-attachments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!