接收电子邮件地址和附件得不到正确的phpmailer

接收电子邮件地址和附件得不到正确的phpmailer

问题描述:

我想发送附件在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 –

在文件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可以指导我成功地附上附件 –