March 26, 2012

Can we add images into outlook mail using php?

Question by harismahesh

I have a Create task page. So once Task is created, and if user admin clicks mail button. Outlook will open and add the subject and body which I typed.

But my doubt is can I add an image and also can we change teh font color in Message using code itself. I am a newbie in this thats why the dumb doubt.

<a href="mailto:xxxx@xxxx.com?subject=Any Subject&body= Any Topics">Mail</a>>

Answer by Starx

Outlook is just an email application, which shows email as it appears.

There is no such thing as Outlook Compatible email.

You should provide direct link to images where you are sending a HTML email. Here is simple example of doing this using native mail()[docs] function.

<?php
$subject = 'Email with image';
$message = '
    <html>
    <head>
      <title>Email with image</title>
    </head>
    <body>
      <p><img src="http://mydomain.com/direct/link/toimage.jpg" /></p>
    </body>
    </html>';

$headers  = 'MIME-Version: 1.0' . "rn";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";

// Additional headers
//..................

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

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!