It's day 5 of reading expert analysis, white papers and a myriad of posted mailer classes, but I seem to be so far away of constructing my PHP script to prepare and send a text and attachment email.

Below is the "hash" of different codes I have been able to put together. I am no longer receiving any errors, but absolutely nothing "seems" to happen when I run the following script. ( I have checked the specified file exists in the designated folder).

Anyone who can help, and perhaps explain what part(s) are incorrect and why, I would be grateful.

$to = "martin.thorburn@tiscali.co.uk";
 
$subject = "A test email";
 
$random_hash = md5(date('r', time()));

$headers = "From: [email]martin.thorburn@tiscali.co.uk[/email]";
 
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
 
$attachment = chunk_split(base64_encode(file_get_contents("../Filestore/Attach.zip")));
 
//sample of text
$headers .= "\r\nContent-Type: text/plain; charset='iso-8859-1'; boundary=\"PHP-text-".$random_hash."\"";
$headers .= "Content-Transfer-Encoding: 7bit";
$message='\n';
$message.= $_POST['FirstName'];
$message.=' ';
$message.= $_POST['LastName'];
$message.=' of ';
$message.= $_POST['CoName'];
$message.=' has submitted the following Sub-Contractor Form details from your web site\n\n';
//end sample of text

$headers .= "--PHP-text--$random_hash--";

$headers .= "\r\nContent-Type: application/zip; name=Attach.zip; charset='iso-8859-1'; boundary=\"PHP-attach-".$random_hash."\"";
$headers .= "Content-Transfer-Encoding: base64";
$headers .= "Content-Disposition: attachment";
 
$attachment;

$headers .= "--PHP-attach--$random_hash--";
$headers .= "--PHP-mixed-$random_hash--"; 

if(mail($to, $subject, $message, $headers)) {
//the rest of the tested mail parameters follow

this one works and is being used within the office.

$from = "From: <martin.thorburn@tiscali.co.uk>";  
    
        $fileatt = "PDF/";
		$fileatt .= $filename;
        $fileatttype = "application/pdf"; 
		$fileattname .= $filename;
    
        $headers = "From: $from";

		$messageletter = "what ever text you would like in here. It can be huge and use \n to start a new line within the email";
        
        $file = fopen( $fileatt, 'rb' ); 
        $data = fread( $file, filesize( $fileatt ) ); 
        fclose( $file );


        $semi_rand = md5( time() ); 
        $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 
    
        $headers .= "\nMIME-Version: 1.0\n" . 
                    "Content-Type: multipart/mixed;\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" . 
                $messageletter . "\n\n";
    
        $data = chunk_split( base64_encode( $data ) );
                 
        $message .= "--{$mime_boundary}\n" . 
                 "Content-Type: {$fileatttype};\n" . 
                 " name=\"{$fileattname}\"\n" . 
                 "Content-Disposition: attachment;\n" . 
                 " filename=\"{$fileattname}\"\n" . 
                 "Content-Transfer-Encoding: base64\n\n" . 
                 $data . "\n\n" . 
                 "--{$mime_boundary}--\n";

        if( mail( $to, $subject, $message, $headers ) ) {
         
            echo "<p>The email was sent.</p>"; 
         
        }
        else { 
        
            echo "<p>There was an error sending the mail.</p>"; 
         
        }
This question has already been answered. Start a new discussion instead.