Skip to content Skip to sidebar Skip to footer

File Attachment Not Going In Mail In Php

I am making a form in html in which there is an upload button and some details of the user.I want to send all the details of the form along with file uploaded from the user.But it

Solution 1:

you can use phpmailer class along with this function

functionsend_mail_with_attachment($upload_path,$from_name,$from_mail,$replyto,$to,$message,$filenames,$subject) {


$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output$mail->setFrom($from_mail, $from_name);
$mail->addAddress($to);     // Add a recipient$mail->addBCC('test@test.net');
 $mail->addBCC('test@test.com');
$mail->addAttachment($upload_path.$filenames);         // Add attachments// Optional name$mail->isHTML(true);                                  // Set email format to HTML$mail->Subject = $subject;
$mail->Body    = $message;
$mail->AltBody = $message;

if(!$mail->send()) {

    echo'Message could not be sent.';
    echo'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo'success';
}




    } 

just download the phpmailer class and require_once('includes/php_mailer/class.phpmailer.php'); include it in your code . i hope it will work for you

Solution 2:

There's a better way to send email using php. I would recommend you try using phpMailer. You can get it here. phpMailer is quite good and handles attachments very well

Solution 3:

try this its working fine..!

<divclass="element"><ahref="http://tenmiles.com/index.php"><imgsrc="logo.gif"></a><br><br><divclass="new"></div><center><h2>Submit Your Information  below</h2></center><formaction="1.php"method="post"enctype="multipart/form-data"autocomplete="off"><!-- <span class="erorr"> ---><divclass="image"></div><label>Name:</label><inputid="box1"placeholder="Type here"type="text"name="Name"required><br><br><label>Email:</label><inputid="box2"placeholder="Type here"type="email"name="Email"required ><br><br><label>Time period in which you will join</label><selectid ="myList"name="Time" ><optionvalue="Immediate"required>Immediate</option><optionvalue="Less than one month">Less than one month</option><optionvalue="1 month">1 month</option><optionvalue="2 months">2 months</option></select><br><br><label>Linkedin Link:</label><inputtype="text"id="box3"name="Linkedin_ID"placeholder="https://www"required ><br><br><labelfor="workexcel">What job responsibilities and duties do you excel at?</label><textareaname="excel"placeholder="Type Here.."id="add"rows="2"cols="2"maxlength="300"required></textarea><br><br><label>Tell me about a challenge or conflict you've faced at work, and how you dealt with it.</label><textareaname="conflict"placeholder="Type Here.."rows="2"cols="2"maxlength="300"required ></textarea><br><br><labelfor"twork">What is your greatest professional achievement?</label><textareaname="Professional"placeholder="Type here.."id="twork"rows="10"cols="30"maxlength="300"required></textarea><br><br><br><labelfor="det">Tell us something about Yourself</label>&nbsp;&nbsp;<textareaname= "About"placeholder="Type here.."id="det"rows="10"cols="30"maxlength="300"required ></textarea><br><br><labelfor="resume">Attach Your Resume here </label><inputtype="file"name="smtpimg"><br><br><inputtype="checkbox"value="Area"required>&nbsp;&nbsp;I understand that I am applying for the job which is of my Area of field.
    <br><h1><inputid="submit"type="Submit"name="submit"value="Submit"></h1><!-- </span> --></form></div></body></head></html>

your php here with smtp code

<?phpinclude"PHPMailer_5.2.4/class.phpmailer.php"; 
if(isset($_POST["submit"])){
               // $email = $_POST["emailfrom"];$target_dir = "smtpimg/";
$target_file= $target_dir .time().basename($_FILES['smtpimg']['name']);
$movefile=move_uploaded_file($_FILES['smtpimg']['tmp_name'], $target_file);
$message = "<table width='800' border='1' cellspacing='0' cellpadding='8' bordercolor='#CCCCC'>      
        <tr>        
              <td colspan='2' bgcolor='#CDD9F5'><strong>Candidate Details</strong></td>               
        </tr> 
        <tr>        
            <td width='168' bgcolor='#FFFFEC'><strong>Candidate Name</strong></td>        
            <td width='290' bgcolor='#FFFFEC'>'".$_POST['Name']."'</td>      
        </tr>      
        <tr>        
            <td bgcolor='#FFFFDD'><strong>E-mail ID</strong></td>        
            <td bgcolor='#FFFFDD'>'".$_POST['Name']."'</td>      
        </tr>
        <tr>        
            <td bgcolor='#FFFFDD'><strong>Time required by user to Join the Company</strong></td>        
            <td bgcolor='#FFFFDD'>'".$_POST['Email']."'</td>     
        </tr>                        
        <tr>        
            <td bgcolor='#FFFFDD'><strong>Linkedin ID</strong></td>        
            <td bgcolor='#FFFFDD'>'".$_POST['Linkedin_ID']."'</td>     
        </tr>                        
        <tr>        
            <td bgcolor='#FFFFDD'><strong>Excel</strong></td>        
            <td bgcolor='#FFFFDD'>'".$_POST['excel']."'</td>
        </tr>                        
            <tr>        
            <td bgcolor='#FFFFDD'><strong>challenge</strong></td>        
            <td bgcolor='#FFFFDD'>'".$_POST['conflict']."'</td>     
        </tr>                      
        <tr>        
            <td bgcolor='#FFFFDD'><strong>professional</strong></td>        
            <td bgcolor='#FFFFDD'>'".$_POST['Professional']."'</td>  
        </tr>                        
        <tr>        
            <td bgcolor='#FFFFDD'><strong>details</strong></td>        
            <td bgcolor='#FFFFDD'>'".$_POST['About']."'</td>     
        </tr>                        
     </table>";
     print_r($message);
$mail = new PHPMailer(); 

$mail->IsSMTP(); 
$mail->SMTPDebug = 1; 
$mail->SMTPAuth = true; 
$mail->SMTPSecure = 'ssl'; 
$mail->Host = "smtp.gmail.com";

$mail->Port = 465; 
$mail->IsHTML(true);
$mail->Username = "yourusername@gmail.com";
$mail->Password = "yourgmailpassword";
$mail->AddReplyTo("reply@yourdomain.com", "Reply name");
$mail->AddAddress($_POST['Email'],'ashu');
$mail->Subject = "SMTP Receivced";
$mail->Body = "<b>Succesfully SMTP Receivced</b>";
$mail->AddAttachment($target_file);
$mail->MsgHTML($message);
$text = 'Text version of email';
$html = '<html><body>HTML version of email</body></html>';
$file = 'index.php';
$crlf = "\n";
$hdrs = array(
              'From'    => 'you@yourdomain.com',
              'Subject' => 'Test mime message'
              );
if($mail->send($hdrs))
 {
echo"<script> alert('Successfully Mailed');window.location = 'pra-2.php';</script>";
}
else{
echo"Mailed Error: " . $mail->ErrorInfo;
}
}
?>

enter image description here

Post a Comment for "File Attachment Not Going In Mail In Php"