Mail Sending – Header Properties

This example will illustrate the mail sending with attachment and declaring MIME type as to HTTP understand the content.

The below are the code will illustrate the mail sending process to the Administrator once the user submitted their information using Contact US or More Info page.

The below steps will explain the File Upload process if user uploaded any documents,

$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path);

Initialize the mail server,

ini_set('SMTP','mail server name');

The below will explain you the mail send to the administrator with the HTML view of user submitted information.

$web=$_POST['website'];
$to = "adminmail@domainname.com";
$subject = "Subject Declaration";
$from_name = "Some Text about the Header";
$message = "

Dear Admin,
Below is the Request added by the Customer.

Name : " .$_POST['pname'] . "
Email ID : " . $_POST['email'] ."
Phone : " . $telephone ."
Country : " .$_POST['country'] . "
Company Name : " .$_POST['cname'] . "
Website : " .$web . "
Project : " .$_POST['project'] . "
Description : " .$_POST['pdesc']. "
Thanks,
" .$_POST['pname'] . "

";
$from = $_POST['email'];

Here we will are checking whether user uploaded any document if yes sent that to Administrator,

if($_FILES['uploadedfile']['name']!='')
{
$file = fopen( $target_path, 'rb' );
$data = fread( $file, filesize( $target_path ) );
fclose( $file );
$semi_rand = md5( time() );
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

$fileattname='application/octet-stream';
$fileatttype = "application/".$_FILES['uploadedfile']['type'];

$headers.= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$headers .= "From:{$from}";

$message.= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message. "\n\n";

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

$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatttype};\n" .
" name=\"{$fileattname}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$_FILES['uploadedfile']['name']}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
mail($to, $subject, $message, $headers);

}
else
{

$headers .= "MIME-Version:1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From:{$from}";
mail($to, $subject, $message, $headers);

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: