2016-10-19 4 views
0

私は自分の個人的およびキャリアの詳細を記入し、履歴書を添付するようにユーザーに尋ねるhtml形式を採用しています。私はそれらの詳細(フォームデータと添付ファイル)をPHPを使用して電子メールに送信したいと思います....どんな助けも大いに感謝されます....phpの他のフォームデータと一緒にメールを介して添付ファイルを送信するには?

私はこのメールを送信するためのコードです...これを使用しています

<?php 
// Settings - working good 
$name  = "Name goes here"; 
$email  = "[email protected]"; 
$to   = "$name <$email>"; 
$from  = "Vijay"; 
$subject  = "Here is your attachment"; 
$mainMessage = "Hi, here's the file."; 
$attachments = $_FILES['attachment']; 

if(empty($_POST['title'])  || 

    empty($_POST['exp'])   || 

    empty($_POST['skill'])   || 

    empty($_POST['qual'])   || 

    empty($_POST['certf'])   || 

    empty($_POST['domain'])  || 

    empty($_POST['fname'])  || 

    empty($_POST['lname'])  || 

    empty($_POST['phone'])  || 

    empty($_POST['email'])  || 

    empty($_POST['csal'])  || 

    empty($_POST['job'])   || 

// empty($_POST['file'])  || 

    !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)) 

    { 

    echo "No arguments Provided!"; 



    return false; 

    }$title = strip_tags(htmlspecialchars($_POST['title'])); 

$exp = strip_tags(htmlspecialchars($_POST['exp'])); 

$skill = strip_tags(htmlspecialchars($_POST['skill'])); 

$qual = strip_tags(htmlspecialchars($_POST['qual'])); 

$certf = strip_tags(htmlspecialchars($_POST['certf'])); 

$domain = strip_tags(htmlspecialchars($_POST['domain'])); 

$fname = strip_tags(htmlspecialchars($_POST['fname'])); 

$lname = strip_tags(htmlspecialchars($_POST['lname'])); 

$phone = strip_tags(htmlspecialchars($_POST['phone'])); 

$email_address = strip_tags(htmlspecialchars($_POST['email'])); 

$csal = strip_tags(htmlspecialchars($_POST['csal'])); 

$job = strip_tags(htmlspecialchars($_POST['job'])); 



// File 
//Get uploaded file data 
    $file_tmp_name = $_FILES['attachment']['tmp_name']; 
    $file_name  = $_FILES['attachment']['name']; 
    $file_size  = $_FILES['attachment']['size']; 
    $file_type  = $_FILES['attachment']['type']; 
    $file_error  = $_FILES['attachment']['error']; 

    if($file_error > 0) 
    { 
     die('Upload error or No files uploaded'); 
    } 
    //read from the uploaded file & base64_encode content for the mail 
    $handle = fopen($file_tmp_name, "r"); 
    $content = fread($handle, $file_size); 
    fclose($handle); 
    $encoded_content = chunk_split(base64_encode($content)); 

     $boundary = md5("sanwebe"); 
     //header 
     $headers = "MIME-Version: 1.0\r\n"; 
     $headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n"; 

     //plain text 
     $body = "--$boundary\r\n"; 
     $body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n"; 
     $body .= "Content-Transfer-Encoding: base64\r\n\r\n"; 
     $body .= chunk_split(base64_encode($Message)); 

     //attachment 
     $body .= "--$boundary\r\n"; 
     $body .="Content-Type: $file_type; name=".$file_name."\r\n"; 
     $body .="Content-Disposition: attachment; filename=".$file_name."\r\n"; 
     $body .="Content-Transfer-Encoding: base64\r\n"; 
     $body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n"; 
     $body .= $encoded_content; 
$Message = "You have received a new resume from your website career application form.\n\n"."Here are the details:\n\n 

Title: ".$title."\n 
Experience: ".$exp."\n 
Skill: ".$skill."\n 
Qualification: ".$qual."\n 
Domain: ".$domain."\n 
First Name: ".$fname."\n 
Last Name: ".$lname."\n 
Phone: ".$phone."\n 
Email: ".$email_address."\n\n 

Current Salary: ".$csal."\n\n 

Job: ".$job."\n\n"; 
$data = chunk_split(base64_encode($data)); 
$message .= "--{$mime_boundary}\n" . 
"Content-Type: {$fileatttype};\n" . 
" name=\"{$fileattname}\"\n" . 
"Content-Disposition: attachment;\n" . 
" filename=\"{$fileattname}\"\n" . 
"Content-Transfer-Encoding: base64\n\n" . 
$data . "\n\n" . 
"-{$mime_boundary}-\n"; 
// Send the email 
if(mail($to, $subject, $Message, $headers)) { 
    echo "The email was sent."; 
echo "$fileattname"; 
} 
else { 
    echo "There was an error sending the mail."; 
} 
?> 
+0

これは役に立ちます:[Alredy A](http://stackoverflow.com/questions/12301358/send-attachments-with-php-mail) –

+0

phpmailerクラスhttps://github.com/を使用してくださいPHPMailer/PHPMailer –

答えて

0

チェック次のリンクSend PHP mail with attachment

これは、あなたが

+0

こんにちは、すばやい返信ありがとう...私はこれをもう一度尋ねることができれば申し訳ありません...私はそのコードを使ってみましたが、フォームから他のデータを取得できませんでした。私が使用しているhtml形式を送ることができます.... – Praveen

+0

ここにPHPのメール機能のための私のコードです....これを使用して、私は他のフォームのデータではない添付ファイルを取得する... plsはどこを助ける私は間違っています。 – Praveen

+0

$ body変数を定義する前にコードを入れてください($ messageを定義しています)... もっと助けが必要な場合や理解できない場合はお知らせください – Amrinder

0
探しているものです...私は、添付ファイルを取得しますが、私は間違っているつもりだところではない他の形式のデータが... PLSのに役立ちます

SwiftmailerやZendのような実績のある、よくテストされたライブラリを使いたい\ Mailのようにコードを書くのではなく、

関連する問題