douzhi9478 2017-06-22 18:57
浏览 49

PHPMailer用户附件

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';
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
    • ¥20 关于URL获取的参数,无法执行二选一查询
    • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
    • ¥15 marlin编译错误,如何解决?
    • ¥15 有偿四位数,节约算法和扫描算法
    • ¥15 VUE项目怎么运行,系统打不开
    • ¥50 pointpillars等目标检测算法怎么融合注意力机制
    • ¥20 Vs code Mac系统 PHP Debug调试环境配置
    • ¥60 大一项目课,微信小程序
    • ¥15 求视频摘要youtube和ovp数据集