将表单上载文件作为附件发送,不带数据库

时间:2016-02-09 12:14:19

标签: php forms email attachment

我正在尝试构建简历上传表单,用户将上传文件和数据 我希望不使用数据库将上传的文件和数据发送到我的电子邮件ID。

这是代码。我无法理解问题。没有收到任何电子邮件我需要帮助

<?php
if(isset($_POST['submit']))
{
    //The form has been submitted, prep a nice thank you message
    $output = '<h1>Thanks for your file and message!</h1>';
    //Set the form flag to no display (cheap way!)
    $flags = 'style="display:none;"';

    //Deal with the email
    $to = 'company@gmail.com';
    $subject = 'Careers Form New Upload';

    $message = strip_tags($_POST['message']);
    $attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name'])));
    $filename = $_FILES['file']['name'];

    $boundary =md5(date('r', time())); 

    $headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
    $headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";

    $message="This is a multi-part message in MIME format.
    --_1_$boundary
    Content-Type: multipart/alternative; boundary=\"_2_$boundary\"

    --_2_$boundary
    Content-Type: text/plain; charset=\"iso-8859-1\"
    Content-Transfer-Encoding: 7bit

    $message

    --_2_$boundary--
    --_1_$boundary
    Content-Type: application/octet-stream; name=\"$filename\" 
    Content-Transfer-Encoding: base64 
    Content-Disposition: attachment 

    $attachment
    --_1_$boundary--";

    $name=$_POST['first_name'];
    $skills=$_POST['skills'];
    $jobtitle=$_POST['jobtitle'];
    $company=$_POST['company'];
    $experience=$_POST['experience'];
    $email=$_POST['email'];
    $phone=$_POST['phone'];
    $jobtype=$_POST['jobtype'];
    $availability=$_POST['availability'];
    $description=$_POST['description'];      

    $headers .= "From:".$firstname."<".$email.">";

    $headers=$headers."\r\n";
    $headers=$headers.'Content-type: text/html; charset=iso-8859-1'."\r\n";

    $body = '<table width="400px" border="0"  bordercolor="#003333" align="center" cellpadding="2" cellspacing="2" bgcolor="#EEEEEE" >
        <tr> 
        <td valign="middle" style="font-family:Arial, Helvetica, sans-serif; font-size:10pt; font-weight:bold; color:#000000; padding-left:30px;  border:1px solid #999999;">Name :</td>
        <td style="width:50%; padding-left:20px; border:1px solid #999999;"">'.$name.'</td>
        </tr> 

        <tr> 
        <td valign="middle" style="font-family:Arial, Helvetica, sans-serif; font-size:10pt; font-weight:bold; color:#000000; padding-left:30px;  border:1px solid #999999;">Name :</td>
        <td style="width:50%; padding-left:20px; border:1px solid #999999;"">'.$skills.'</td>
        </tr> 

        <tr> 
        <td valign="middle" style="font-family:Arial, Helvetica, sans-serif; font-size:10pt; font-weight:bold; color:#000000; padding-left:30px;  border:1px solid #999999;">Name :</td>
        <td style="width:50%; padding-left:20px; border:1px solid #999999;"">'.$jobtitle.'</td>
        </tr>

        <tr> 
        <td valign="middle" style="font-family:Arial, Helvetica, sans-serif; font-size:10pt; font-weight:bold; color:#000000; padding-left:30px;  border:1px solid #999999;">Company Name:</td>
        <td style="width:50%; padding-left:20px; border:1px solid #999999;"">'.$company.'</td>
        </tr>

        <tr> 
        <td valign="middle" style="font-family:Arial, Helvetica, sans-serif; font-size:10pt; font-weight:bold; color:#000000; padding-left:30px;  border:1px solid #999999;">Email Id:</td>
        <td style="width:50%; padding-left:20px; border:1px solid #999999;"">'.$experience.'</td>
        </tr> 


        <tr> 
        <td valign="middle" style="font-family:Arial, Helvetica, sans-serif; font-size:10pt; font-weight:bold; color:#000000; padding-left:30px;  border:1px solid #999999;">Contact no:</td>
        <td style="width:50%; padding-left:20px; border:1px solid #999999;"">'.$email.'</td>
        </tr> 

        <tr> 
        <td valign="middle" style="font-family:Arial, Helvetica, sans-serif; font-size:10pt; font-weight:bold; color:#000000; padding-left:30px;  border:1px solid #999999;">Title:</td>
        <td style="width:50%; padding-left:20px; border:1px solid #999999;"">'.$phone.'</td>
        </tr> 

        <tr> 
        <td valign="middle" style="font-family:Arial, Helvetica, sans-serif; font-size:10pt; font-weight:bold; color:#000000; padding-left:30px;  border:1px solid #999999;">State Name:</td>
        <td style="width:50%; padding-left:20px; border:1px solid #999999;"">'.$jobtype.'</td>
        </tr> 

        <tr> 
        <td valign="middle" style="font-family:Arial, Helvetica, sans-serif; font-size:10pt; font-weight:bold; color:#000000; padding-left:30px;  border:1px solid #999999;">Country Name:</td>
        <td style="width:50%; padding-left:20px; border:1px solid #999999;"">'.$availability.'</td>
        </tr> 

        <tr> 
        <td valign="middle" style="font-family:Arial, Helvetica, sans-serif; font-size:10pt; font-weight:bold; color:#000000; padding-left:30px;  border:1px solid #999999;">Description:</td>
        <td style="width:50%; padding-left:20px; border:1px solid #999999;"">'.$description.'</td>
        </tr> 

    </table>';

    //echo "$notes";
    $conn=mail($to,$subject,$message,$headers,$body);

    if ($conn)
    {
    // echo "<script>alert('Thank you for contacting us')<!--</script>";-->
        echo"<script>window.location.href='careers-thank-you.php'</script>";
    }
    else
    {
        echo "There was an error sending this data. Please retry";
    }
}

?> 

0 个答案:

没有答案