Hi all... For more days, I am struggling with one damn concept.. I have created a sample mail sending code which supports to upload our resume and send it to some company person.. I have cleared many bugs and finally it works fine. But the problem is when i host it with web server (live server) and send a mail with attachment of my resume, the mail has sent successfully but the attachment of my resume is not well. This is not attached well in the mail. The contents of the resume are encoded and that encoded format only attached directly to mail body and sent.. I need to do the attachment as a file. I already worked with PHP mailer script with SMTP configuration. It also works fine in localhost, but not functioning (no errors also displayed, only blank page displayed) in web server (live server). Anybody, please help to kill this and make me to win this challenge.. Here is the Code...

<?php 

session_start(); 

$target_path="uploads/";
               
$fileatt_name = $_FILES['uploadval']['name']; 
$fileatt_type = $_FILES['uploadval']['type']; 
$fileatt_tempname=$_FILES['uploadval']['tmp_name'];


$email_subject = "Resume ";


$email_to = "xxx@yyy.com"; 

$fil=$target_path.$_FILES['uploadval']['name'];



if(file_exists($fil))
{
unlink($fil);
/*echo "Sorry file already exists and it has been deleted...";
exit;*/
}



if(move_uploaded_file($_FILES['uploadval']['tmp_name'],$target_path.$_FILES['uploadval']['name'])) 
{



/*print_r ($_FILES);
$target_path.basename($_FILES['uploadval']['tmp_name']*/



$fileatt =$target_path.$_FILES['uploadval']['name'];  

$file = fopen($fileatt,"rb"); 

$data = fread($file,filesize($fileatt)); 


fclose($file); 

$comments = $_REQUEST['comments'];

$data = chunk_split(base64_encode($data)); 

$semi_rand = md5(time());

$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 

$headers = "\n MIME-Version: 1.0 \n";

$headers.="Content-Type: multipart/mixed;\n";

$headers.=" boundary=\"{$mime_boundary}\"\n";

$message=" ";

$message.="\n\n"."\"--{$mime_boundary}\"\n";

$message.="Content-Type: text/plain; charset=\"iso-8859-1?\"\n";

$message.="Content-Transfer-Encoding: 7bit\n";

$message.=$message."\n\n";

/* $message.="--$semi_rand\n\n"; */

$message.="--{$mime_boundary}\n";

$message.="Content-Type: \"{$fileatt_type}\"\n";

$message.="name= \"{$fileatt_name}\"\n";

$message.="Content-Disposition: attachment;\n";

$message.="filename=\"{$fileatt_name}\"\n";

$message.="Content-Transfer-Encoding: base64\n\n";

$message.=$data;

$message.="\n\n"."--{$mime_boundary}--\n";

$message.="Comments :".$comments."\n\n";

$ok = mail($email_to,$email_subject,$message,$headers); 

if($ok)
{ 
echo "<font face=verdana size=2>Thankyou for uploading your resume to our website... We will call you soon if you are getting shortlisted....</font>"; 
} 
else
{ 
echo("Sorry, Unable to send your resume now. Please go back and try again!"); 
} 
}
?>

This is very urgent now... Thanks in advance for your help...!

Member Avatar for diafol

It may be a daft question, but is your form containing the file field set correctly:

enctype="multipart/form-data"

is needed for file upload. I assume you'd get errors if not, right?

I don't know where it is used and what is its purpose..? Pls explain me...?

Member Avatar for diafol
<form ... enctype="multipart/form-data">
...
</form>

This may or may not solve your problem, but either way.

I don't know if you have ever used this before but after using it for some time, I will never send mail without it. It's an amazing class with a lot of ready made functionality, has been around for a long time and is very well documented.

http://phpmailer.worxware.com/

Sorry guys... Still i didnt fix my probs..
Any help will be appreciated..
Its very urgent..

Anyone there....?

This code is working fine in localhost... But with live server, it sends mail, but without attachment.. Why..?

Hi guys.. Please debug this code.. Where i am doing wrong..? Struggling for more than 15 days.. Very urgent

Member Avatar for diafol

Does your remote SMTP mailer allow attachments like this? I know some hosts insist on including a 'flag' with the mail headers before they will send. Does your host have a bank of scripts that they encourage you to use?

Strange........

Are you hosting yourself??
If not, then talk to your hoster about this issue ok?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.