2017-04-23 8 views
2

添付ファイル付きの電子メールをPHPで送信したいと思います。しかし、電子メールアドレスと添付ファイルが私のコードで正しく受信されない。メールアドレスを手動で渡すと正常にメールを送信できますが正常に受信終了に行くことはありません。電子メールアドレスを受信し、添付ファイルがphpmailerで正しく取得されない

<form action="sendemail.php" enctype="multipart/form-data" > 
          <h1 class="cta-title">Its a Call To Action</h1> 
          <div class="cta-desc"> 
           <input type="text" value='<?= $row['catogary'];?>' readonly style="width: 75%"><br><br> 
           <input type="text" value='<?= $row['company_name'];?>' readonly style="width: 75%"><br><br> 
           <input type="text" value='<?= $row['location'];?>' readonly style="width: 75%"><br><br> 
           <input type="text" value='<?= $row['qulification'];?>' readonly style="width: 75%"><br><br> 
           <input type="text" value='<?= $row['catogary'];?>' readonly style="width: 75%"><br><br> 
           <input type="text" value='<?= $row['indate'];?>' readonly style="width: 37.5%">&nbsp; 
           <input type="text" value='<?= $row['expdate'];?>' readonly style="width: 37.5%"> 
           <input type="text" value='<?= $row['email'];?>' ><br> 
           <input type="file" name="uploaded_file" id="uploaded_file" class="text-center center-block well well-sm"> 
           <input type="submit" id="btn" name="btn" class="btn btn-primary" value="Apply"> 
          </div> 
          </form> 

sendemail.php

<?php 
    $email2=$_POST['email']; 
    require_once('PHPMailer/PHPMailerAutoload.php'); 
    //PHPMailer Object 
    $mail = new PHPMailer; 
$mail->IsSMTP(); // enable SMTP 
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only 
$mail->SMTPAuth = true; // authentication enabled 
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail 
$mail->Host = "smtp.gmail.com"; 
$mail->Port = 465; // or 587 
$mail->IsHTML(true); 
$mail->Username = "[email protected]"; 
$mail->Password = "uwucst14xxxx"; 
$mail->SetFrom("[email protected]"); 
$mail->FromName = "Internship Management"; 

//To address and name 
$mail->addAddress($email2); 
//$mail->addAddress("[email protected]"); //Recipient name is optional 

//Address to which recipient will reply 
$mail->addReplyTo("[email protected]", "Reply"); 

//CC and BCC 
//$mail->addCC("CC"); 
//$mail->addCC("CC"); 
//$mail->addBCC("[email protected]"); 

//Send HTML or Plain Text email 
$mail->isHTML(true); 

$mail->Subject = 'CV for internship Vacancy'; 
$mail->Body = "Attached"; 
//$mail->AltBody = "This is the plain text version of the email content"; 
//$mail->AddAttachment($target_path,$CV); 
if (isset($_FILES['uploaded_file']) && $_FILES['uploaded_file']['error'] == UPLOAD_ERR_OK) { 

    $mail->AddAttachment($_FILES['uploaded_file']['tmp_name'],$_FILES['uploaded_file']['name']); 
} 

if(!$mail->send()) 
{ 
    echo "Mailer Error: " . $mail->ErrorInfo; 
    //echo 'Not sent: <pre>'.print_r(error_get_last(), true).'</pre>'; 

} 
else 
{ 
    //echo "Message has been sent successfully"; 
    echo 'Successfully Applied for vacancy'; 
} 

//**end of send e-mail** 
?> 

エラーがある:あなたがこれはあなたのformタグである

<?php 
    $email2=$_POST['email']; 

を使用しているsendemail.phpファイルで

Undefined index: email in /storage/h7/602/1448602/public_html/sendemail.php on line 2 
+0

あなたが問題になっていることは何ですかcing? –

+0

ご迷惑をおかけして申し訳ございません –

+0

あなたのフォームタグには属性がありませんメソッド= "投稿"とmysqlタグはこのコードまたは質問で使用されていないので削除してください –

答えて

0

<form action="sendemail.php" enctype="multipart/form-data" > 

これはHTTPメソッドGETでフォームを送信していますが、POSTである必要があります。 ですから、この行に

<input type="text" value='<?= $row['email'];?>' ><br> 

を変更することによりその

<form action="sendemail.php" enctype="multipart/form-data" method="post"> 

あなたがエラーを修正

Undefined index: email in /storage/h7/602/1448602/public_html/sendemail.php on line 2 

のようなformタグで= "ポスト" 属性メソッドを追加する必要があります

<input type="text" name="email" value='<?= $row['email'];?>' ><br> 
+0

私はこの友達を試しましたが結果は同じです –

+0

@Danith Kumarasingheあなたがエラーを組み込んだ後で答えを編集しました.. –

+0

@Raymonnd Nijiland ...そのエラーは今すぐ重複しています。あなたは添付ファイルを添付するように案内します。 –

関連する問題