使用PHPMailer发送附件文件 [英] Send attachment file using PHPMailer

查看:93
本文介绍了使用PHPMailer发送附件文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,该代码使用PHPMailer使用PHPMailer通过邮件发送附件.我在localhost中尝试了它,它功能完美.但是,一旦我上传到服务器,附件就不会发送.

Here my code that using PHPMailer to send attachment via mail using PHPMailer. I try this out in localhost it function perfectly. But once I upload to my server, the attachment is not sent.

$email = new PHPMailer();
$email->From      = 'john@hotmail.com';
$email->FromName  = 'John';
$email->Subject   = 'Message Subject';
$email->Body      = 'test';
$email->AddAddress( 'william@hotmail.com' );

$file_to_attach = $_FILES["cv"]["tmp_name"];

$email->AddAttachment( $file_to_attach , $_FILES["cv"]["name"]);

return $email->Send();

我无法收到附件文件,无法上传.

I cant receive my attachment file and I upload.

我错过了任何代码吗??

Did I miss out any code..?

推荐答案

<?php 
if(isset($_POST['sbt_resume'])){
    $ext = explode('.',$_FILES['upload_resume']['name']);
    $extension = $ext[1];
    $newname = uniqid();
    $full_local_path = 'resume/'.$newname.'.'.$extension;
    $upld = move_uploaded_file($_FILES['upload_resume']['tmp_name'], "$full_local_path");
    require_once('PHPMailer/class.phpmailer.php');
    $emailid = new PHPMailer();
    $emailid->IsSMTP(); // enable SMTP
    $emailid->SMTPAuth = true; // authentication enabled
    $emailid->Host = "smtp.gmail.com";
    $emailid->Port = 465; // or 587
    $emailid->IsHTML(true);
    $emailid->SMTPSecure = 'ssl';
    $emailid->Username = "yourgmail@gmail.com";
    $emailid->Password = "";
    $emailid->From = "yourgmail@gmail.com";
    $emailid->FromName = $name;
    $emailid->Subject = ".";
    $emailid->Body = "Atachement";
    $emailid->AddAddress("");
    $emailid->AddBCC($email);
    $emailid->AddAttachment($full_local_path);
    $emailid->Send();
    echo "<font style='color: green; margin-top: 10px;'>Thank you for upload your Resume we will get back you soon.</font>";
}
?>

<form class="contact-form clearfix" action="" method="post" enctype="multipart/form-data">
 <div class="row">      
        <!-- col-md-3 -->
        <div class="col-md-4 col-sm-4 col-xs-4">
            <div class="input-label">
                <p style="padding-top: 10px;">upload <span>*</span></p>
            </div>
        </div>
        <div class="col-md-4 col-sm-4 col-xs-4">
                <input accept="" type="file" name="upload_resume" class="valid" style="border: 1px solid #E0E0E0;padding: 12px 15px;">
        </div>
        <!-- col-md-9 -->
    </div>
    <!-- row --> 

    <!-- row -->
    <div class="row">
        <div class="col-md-12 col-sm-12 col-xs-12">
            <p class="contact-button clearfix">                    
                <span><input type="submit" name="sbt_resume" value="Send" id="submit-contact"></span>
            </p>
        </div>
        <!-- col-md-12 -->
    </div>
    <!-- row --> 
</form>

这篇关于使用PHPMailer发送附件文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆