2017-04-23 83 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 = "getinternshipuwu[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** 
?> 

錯誤是:

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

你是什麼問題?慶安? –

+0

抱歉的錯誤。現在檢查 –

+0

你的表單標記缺少屬性method =「post」,並刪除mysql標記,因爲在此代碼或問題中沒有使用mysql –

回答

0

在文件sendemail.php您使用

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

這是你的表單標籤。

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

這是用HTTP方法GET發送表單,但它需要POST。 所以,你需要在表單標籤添加屬性的方法= 「後」 像這樣

<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 

通過改變這一行

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

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

我試過這個朋友但結果相同 –

+0

@Danith Kumarasinghe ive編輯答案後,你包括錯誤.. –

+0

謝謝@Raymonnd Nijiland ...現在錯誤是coorect可以指導我成功地附上附件 –

相關問題