Jump to content

[SOLVED] Help with emailing an attachment


elis

Recommended Posts

Here is my full script (it's supposed to email the document after it's been uploaded)

 

<?php
/* Test emailing ability */

require_once '../startups.php';

if ( isset($_POST['submit_candidate']) ){

if ( is_uploaded_file($_FILES['resume_doc']['tmp_name']) ){
$resume_doc = fopen($_FILES['resume_doc']['tmp_name'], 'rb');
$resume_filetype = $_FILES['resume_doc']['type'];
$resume_filename = $_FILES['resume_doc']['name'];

						} else {
$resume_doc 		= null;
$resume_filetype 	= null;
$resume_filename 	= null;
						}
if(!empty($resume_doc)){
	$ext = end(explode('.',$resume_doc));
	if($ext = "doc"){
	$type ="doc";
		}
			else 
	$type = "docx";

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

$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
$headers = "From: $from\r\n" .
         "MIME-Version: 1.0\r\n" .
         "Content-Type: multipart/mixed;\r\n" .
         " boundary=\"{$mime_boundary}\"";
$message = "This is a multi-part message in MIME format.\n\n" .
         "--{$mime_boundary}\n" .
         "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
         "Content-Transfer-Encoding: 7bit\n\n" .
         $message . "\n\n";


// The message
$message = "Line 1\nLine 2\nLine 3";

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);
$message .= "--{$mime_boundary}\n" .
         "Content-Type: $resume_filetype;\n" .
         " name=\"$resume_filename\"\n" .
         //"Content-Disposition: attachment;\n" .
         //" filename=\"{$fileatt_name}\"\n" .
         "Content-Transfer-Encoding: base64\n\n" .
         $data . "\n\n" .
         "--{$mime_boundary}--\n";

// Send
mail('email@emailplace.com','Test Subject',$message, $headers);
} 

echo "mail sent and $type"; 

}


else {
echo "<form id=\"new\" action=\"sendmail.php\" method=\"post\" enctype=\"multipart/form-data\">
<div class=\"field-label\"><label for=\"resume_doc\">Formatted Word Resume</label>:</div>
	<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"1000000\" />
			<input id=\"resume_doc\" name=\"resume_doc\" type=\"file\" />
			<br>
<input type=\"submit\" name=\"submit_candidate\" value=\"Submit\" /> <input type=\"button\" value=\"Reset\"/></form>"; }
?>

 

and I receive this error:

 

Warning: base64_encode() expects parameter 1 to be string, resource given in /www/atest/sendmail.php on line 27

 

The email is sent however the attachment isn't.

I'm not familiar with the mail() function at all.

Can anyone spot what I've done wrong?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.