Jump to content

email attachment


An7hony

Recommended Posts

Hi I need to attach a file to an email from my database records

 

So far i have: 

function sendNewCandidate($user, $email, $agent, $jobtitle, $useremail, $cv) {
  $from = "From: ".$user." <".$useremail.">";
      $subject = "New applicant";
  $attachment = chunk_split(base64_encode(file_get_contents('http://www.website.co.uk/$cv')));
      $body = $agent.",\n\n"
      ."".$user." has applied for your job ".$jobtitle."."
      ."We suggest you go to your admin panel and view the CV"
      ."- Thank you. ";
  
      return mail($email, $subject, $body, $from);
  }
};

 

$cv holds the location of the file for the user.

These files are generally .doc

 

I have read i may need something like this:

Content-Type: application/zip; name="attachment.zip" 

Content-Transfer-Encoding: base64 

Content-Disposition: attachment 

 

but how would i incorporate this?

 

Thanks guys

 

Link to comment
https://forums.phpfreaks.com/topic/227850-email-attachment/
Share on other sites

i have just read this, so i'm going to try it out:

 

$my_file = "somefile.zip";
$my_path = $_SERVER['DOCUMENT_ROOT']."/your_path_here/";
$my_name = "Olaf Lederer";
$my_mail = "[email protected]";
$my_replyto = "[email protected]";
$my_subject = "This is a mail with attachment.";
$my_message = "Hallo,\r\ndo you like this script? I hope it will help.\r\n\r\ngr. Olaf";
mail_attachment($my_file, $my_path, "[email protected]", $my_mail, $my_name, $my_replyto, $my_subject, $my_message);

 

 

Link to comment
https://forums.phpfreaks.com/topic/227850-email-attachment/#findComment-1174920
Share on other sites

At the moment i am getting:

 

Warning: filesize() [function.filesize]: stat failed for http://www.website.co.uk/elements/$cv in /home/*****/public_html/elements/mailer.php on line 93

 

Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/******/public_html/elements/mailer.php on line 95

 

 

function sendNewCandidate($user, $email, $agent, $jobtitle, $useremail, $cv) {
    $file = 'http://www.website.co.uk/elements/$cv';
    $file_size = filesize($file);
    $handle = fopen($file, "r");
    $content = fread($handle, $file_size);
    fclose($handle);
    $content = chunk_split(base64_encode($content));
    $uid = md5(uniqid(time()));
    $name = basename($file);
    $subject = "New applicant";
    $header = "From: ".$user." <".$useremail.">\r\n";
    $header .= "Reply-To: ".$useremail."\r\n";
    $header .= "MIME-Version: 1.0\r\n";
    $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
    $header .= "This is a multi-part message in MIME format.\r\n";
    $header .= "--".$uid."\r\n";
    $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
    $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
    $header .= $agent.",\n\n"
      ."".$user." has applied for your job ".$jobtitle."."
      ."We suggest you go to your admin panel and view the CV"
      ."- Website. ";
    $header .= "--".$uid."\r\n";
    $header .= "Content-Type: application/octet-stream; name=\"".$cv."\"\r\n"; // use different content types here
    $header .= "Content-Transfer-Encoding: base64\r\n";
    $header .= "Content-Disposition: attachment; filename=\"".$cv."\"\r\n\r\n";
    $header .= $content."\r\n\r\n";
    $header .= "--".$uid."--";
    return mail($email, $subject, "", $header);
    }
};

 

can anyone explain?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/227850-email-attachment/#findComment-1174939
Share on other sites

ok i am not getting any errors now. This is what i have:

 

function sendNewCandidate($user, $email, $agent, $jobtitle, $useremail, $cv) {
    $file = $_SERVER['DOCUMENT_ROOT']."/elements/".$cv;
    $file_size = filesize($file);
    $handle = fopen($file, "r");
    $content = fread($handle, $file_size);
    fclose($handle);
    $content = chunk_split(base64_encode($content));
    $uid = md5(uniqid(time()));
    $name = basename($file);
$subject = "New applicant";
    $header = "From: ".$user." <".$useremail.">\r\n";
    $header .= "Reply-To: ".$useremail."\r\n";
    $header .= "MIME-Version: 1.0\r\n";
    $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
    $header .= "This is a multi-part message in MIME format.\r\n";
    $header .= "--".$uid."\r\n";
    $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
    $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
    $header .= $agent.",\n\n"
      ."".$user." has applied for your job ".$jobtitle."."
      ."We suggest you go to your admin panel and view the CV"
      ."- Web Site. ";
    $header .= "--".$uid."\r\n";
    $header .= "Content-Type: application/octet-stream; name=\"".$name."\"\r\n"; // use different content types here
    $header .= "Content-Transfer-Encoding: base64\r\n";
    $header .= "Content-Disposition: attachment; filename=\"".$name."\"\r\n\r\n";
    $header .= $content."\r\n\r\n";
    $header .= "--".$uid."--";
    return mail($email, $subject, "", $header);
    }
};

 

Although instead of the file being attached to the email i am getting

 

0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAAAAAAAAAABAAAAIgAAAAAAAAAA

etc etc

 

Link to comment
https://forums.phpfreaks.com/topic/227850-email-attachment/#findComment-1174965
Share on other sites

this is similar to what i'm getting instead of the file attachment:

 

 

This is the body of the message.

--frontier

Content-Type: application/octet-stream

Content-Transfer-Encoding: base64

 

PGh0bWw+CiAgPGhlYWQ+CiAgPC9oZWFkPgogIDxib2R5PgogICAgPHA+VGhpcyBpcyB0aGUg

Ym9keSBvZiB0aGUgbWVzc2FnZS48L3A+CiAgPC9ib2R5Pgo8L2h0bWw+Cg==

--frontier--

 

http://en.wikipedia.org/wiki/MIME

 

Link to comment
https://forums.phpfreaks.com/topic/227850-email-attachment/#findComment-1174972
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.