Send mail with html table and image attachement (sloved)

code for html table:

//validation and others stuff

$info = 
		'<html>
                <head>
                    <title>Get Free Quotes</title>
                </head>
                        <body>
                            <table  border="1" cellspacing="0" width="60%" cellpadding="10px">
                                <tr>
                                    <td>Name:</td>
                                    <td>'.$name.'</td>
                                </tr>
                                <tr>
                                    <td>Email:</td>
                                    <td>'.$email.'</td>
                                </tr>
                                <tr>
                                    <td>Phone:</td>
                                    <td>'.$phone.'</td>
                                </tr>
                                <tr>
                                    <td>Services:</td>
                                    <td>'.$services.'</td>
                                </tr>
                                <tr>
                                    <td>Message:</td>
                                    <td>'.$message.'</td>
                                </tr>
                            </table>
                        </body>
                    </html>
                ';
		
		$headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
		$headers .='From:' .$email;
        $subject = "Mail From Client";
        $mailTo = "satish.innovstudio@gmail.com";
		// you must test the returned value from the mail() call
		// if it is a false value, setup a message in the $errors array
		mail($mailTo, $subject, $body,$headers);
	}

i was not able to insert image attachment on above code so here separate code for sending mail with attachment .

//validation

	//Get uploaded file data using $_FILES array
	$tmp_name = $_FILES['attachment']['tmp_name']; // get the temporary file name of the file on the server
	$name	 = $_FILES['attachment']['name']; // get the name of the file
	$size	 = $_FILES['attachment']['size']; // get size of the file for size validation
	$type	 = $_FILES['attachment']['type']; // get type of the file
	$error	 = $_FILES['attachment']['error']; // get the error (if any)

	//validate form field for attaching the file
	if($error > 0)
	{
		die('Upload error or No files uploaded');
	}

	//read from the uploaded file & base64_encode content
	$handle = fopen($tmp_name, "r"); // set the file handle only for reading the file
	$content = fread($handle, $size); // reading the file
	fclose($handle);				 // close upon completion

	$encoded_content = chunk_split(base64_encode($content));
	$boundary = md5("random"); // define boundary with a md5 hashed value

	//header
	$headers = "MIME-Version: 1.0\r\n"; // Defining the MIME version
	$headers .= "From:".$from_email."\r\n"; // Sender Email
	$headers .= "Reply-To: ".$reply_to_email."\r\n"; // Email address to reach back
	$headers .= "Content-Type: multipart/mixed;"; // Defining Content-Type
	$headers .= "boundary = $boundary\r\n"; //Defining the Boundary
		
	//plain text
	$body = "--$boundary\r\n";
	$body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
	$body .= "Content-Transfer-Encoding: base64\r\n\r\n";
	$body .= chunk_split(base64_encode(
	    //$message
	   'Full Name :'.$sender_name."\n".
	   'State :'.$state."\n".
	   'Address :'.$address."\n".
	   'Phone :'.$phone."\n".
	   'Email Address :'.$email."\n".
	   'Services:'.$services."\n".
	    'Subject:'.$subject."\n".
	   'Message :'."\n".$message
	));
		
	//attachment
	$body .= "--$boundary\r\n";
	$body .="Content-Type: $type; name=".$name."\r\n";
	$body .="Content-Disposition: attachment; filename=".$name."\r\n";
	$body .="Content-Transfer-Encoding: base64\r\n";
	$body .="X-Attachment-Id: ".rand(1000, 99999)."\r\n\r\n";
	$body .= $encoded_content; // Attaching the encoded file with email
	
	$sentMailResult = mail($recipient_email, $subject, $body, $headers);


im unable to insert html table in this code but i receive image attachment

$body .= chunk_split(base64_encode(
	    //$message
	   'Full Name :'.$sender_name."\n".
	   'State :'.$state."\n".
	   'Address :'.$address."\n".
	   'Phone :'.$phone."\n".
	   'Email Address :'.$email."\n".
	   'Services:'.$services."\n".
	    'Subject:'.$subject."\n".
	   'Message :'."\n".$message
	));

what i want is that i want to receive mail with html table format with image attachment…

Solution:

//Get uploaded file data
    $file_tmp_name    = $_FILES['my_file']['tmp_name'];
    
    $file_name        = $_FILES['my_file']['name'];
    $file_size        = $_FILES['my_file']['size'];
    $file_type        = $_FILES['my_file']['type'];
    $file_error       = $_FILES['my_file']['error'];

    if($file_error > 0)
    {
        die('Upload error or No files uploaded');
    }
    //read from the uploaded file & base64_encode content for the mail
    $handle = fopen($file_tmp_name, "r");
    $content = fread($handle, $file_size);
    fclose($handle);
    $encoded_content = chunk_split(base64_encode($content));
		
	$boundary = md5("sanwebe");
        //header
		$subject = "Mail From Client";
        $mailTo = "satish.innovstudio@gmail.com";
        $headers = "MIME-Version: 1.0\r\n";
        $headers .='From:' .$email;
        $headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n";
       
        //plain text
        $body = "--$boundary\r\n";
        $body .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
        $body .= "Content-Transfer-Encoding: base64\r\n\r\n";
        $body .= chunk_split(base64_encode($info));
       
        //attachment
        $body .= "--$boundary\r\n";
        $body .="Content-Type: $file_type; name=".$file_name."\r\n";
        $body .="Content-Disposition: attachment; filename=".$file_name."\r\n";
        $body .="Content-Transfer-Encoding: base64\r\n";
        $body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n";
        $body .= $encoded_content;
		mail($mailTo, $subject, $body,$headers);

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.