Click here to Skip to main content
14,932,457 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

following email sript works with the file attachament
how to design html template for the following mail

PHP
if(isset($_POST['submit']))
    {
        //The form has been submitted, prep a nice thank you message
        $output = '<h3>Thanks for your file and message!</h3>';

        //Deal with the email
        $to = $_POST['email'];
        $subject = $_POST['subject'];

        $email = strip_tags($_POST['email']);
        $name  = strip_tags($_POST['name']);
        $skype = strip_tags($_POST['skype']);
        $message = "Posted Question: ".strip_tags($_POST['message'])."\n"."\n";
        $attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name'])));

        $target_dir = "uploads/";
        $target_file = $target_dir . basename($today._.$time._.$_FILES["file"]["name"]);

        if($_FILES['file']['name'] != ""){
           move_uploaded_file($_FILES['file']['tmp_name'], $target_file);
        }


        $boundary =md5(date('r', time()));

        $headers = "From: $to\r\nReply-To: $to";
        $headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";

    $message .= "Name: ".$name."\n"."\n";

    $message .= "Email: ".$email."\n"."\n";

    $message .= "Skype ID: ".$skype."\n"."\n";


 $message="This is a multi-part message in MIME format.

--_1_$boundary
Content-Type: multipart/alternative; boundary=\"_2_$boundary\"

--_2_$boundary
Content-Type: text/plain; charset=\"iso-8859-1\"
Content-Transfer-Encoding: 7bit

$message

--_2_$boundary--
--_1_$boundary
Content-Type: application/octet-stream; name=\"$filename\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment

$attachment
--_1_$boundary--";

        mail($to, $subject, $message, $headers);
    }
Posted

An email can be added to the HTML document and sent to the client. Those HTML styles would be then rendered as the styles of the email itself.

For example, you can think of the following HTML markup

HTML
<div style="font-family: 'Segoe UI'; padding: 10px; color: #cecece">
   Hello, this is the email body. 
</div>


.. you can pass that entire code, as a string, to the body of the email. Once the email client would get it, it will render it as the styles would guide. There is no other special language to learn while designing the emails. You can design a web page, add data to it using the variables, fill the body and elements and just send it.
   
Comments
Arun-23 18-Nov-14 5:24am
   
i had tried in the mail but it taking as a string not as tag

$message = "<div style=\"background:red;height:100px;width:100px;display:block;\">dfsdf</div>";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1". "\r\n";
Afzaal Ahmad Zeeshan 18-Nov-14 5:33am
   
That is because, here it will be a string. Once sent, then it will be converted as a tag. Why don't you try sending an email to your gmail account? You will see, that it will be converted to HTML markup once downloaded by your client; Web or application.
Arun-23 18-Nov-14 5:46am
   
yeah i had send but <div style=\"background:red;height:100px;width:100px;display:block;\">sample</div> like this it displays insted of sample
Afzaal Ahmad Zeeshan 18-Nov-14 5:56am
   
Only sample is displayed on the page at all?
Arun-23 18-Nov-14 6:00am
   
just for example i had said you sample.. need to display for above mail like bgcolor font color for message
Afzaal Ahmad Zeeshan 18-Nov-14 6:03am
   
So that is a good step. Your example is telling that that markup is being used. Why is your color not being applied? It must have been applied, or I guess the client is removing it on himself.

Since this HTML markup is understood and rendered as a simple sample text, then there is no issue with creating the entire HTML page to send as an email.

You're going good. This is the way it would be/ should be done. :)
You need to instruct include the instruction to interpret content as email:
(where my parameter array for SMTP mail is in $mailPars):

PHP
$mailPars[3] = "MIME-Version: 1.0" . "\r\n"
                . "Content-type:text/html;charset=utf8" . "\r\n"
                . $mailPars[3];

Without this your tags are just considered text.

   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900