generating email with inline image

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pradeepjain
    Contributor
    • Jul 2007
    • 563

    generating email with inline image

    hii guys,
    I am storing a image in a database in form of blob and now i want to send that image as a inline image in a mail ..how to do it..
    this is the code ..plzz help

    [PHP]<?php
    mysql_connect(" localhost","roo t","12345");
    mysql_select_db ("pyz");

    $str_sql="selec t * from xyz where id= '".$_GET['Id']."'";;
    $Colloquiums1 = array();
    $i=0;

    $res_id=mysql_q uery($str_sql);
    while ($sub_row=mysql _fetch_array($r es_id)) {
    $tmp1 = array(
    I am storing it here
    );
    $Colloquiums1[$i++] = $tmp1;
    }
    $ID=$Colloquium s1[0]['ID'];
    $nid=$ID;
    $name=strtouppe r($Colloquiums1[0]['name']);
    $picname=$Collo quiums1[0]['picname'];
    $address=$Collo quiums1[0]['address'];


    // subject
    $subject = 'admitcard';

    // message
    $message = '
    <html>
    <head>
    <title>Birthd ay Reminders for August</title>
    </head>
    <body>
    <div id="textcontent ">
    <h3>Admit Card</h3>
    <table align="center" width="100%" border="1" cellspacing="2" cellpadding="2" id="img1">
    <tr>
    <td align="left">Re f=$ID</td>
    </tr>
    </table>
    <table align="center" width="100%" border="0" cellspacing="2" cellpadding="2" id="img1">
    <tr>
    <td>Name</td>
    <td>:</td>
    <td><b>' . $name . '</b></td>
    </tr>
    <tr>
    <td>pic</td>
    <td>:</td>
    <td><p>'. print("<img src='/phdstudents/admitcardpic.ph p?Id='". $ID ."'>") .'</p></td>
    </tr>
    </table>
    <table>This is a automated email(admitcard ) generated.Copyr ight@IIA.</table>
    </body>
    </html> ';

    // To send HTML mail, the Content-type header must be set
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    // Additional headers
    $headers .= 'To: xyz@gmail.com, Kelly <kelly@example. com>' . "\r\n";
    $headers .= 'From: webmaster <webmaster@iiap .res.in>' . "\r\n";
    $headers .= 'Cc: testcom' . "\r\n";
    $headers .= 'Bcc: cc@example.com' . "\r\n";

    // Mail it
    mail($to, $subject, $message, $headers);

    ?>
    [/PHP]


    this is the admitcardpic.ph p where pic is generated

    [PHP]<?php
    error_reporting (E_ALL);
    $link = mysql_connect(" localhost", "root", "12344") or die("Could not connect: " . mysql_error());

    mysql_select_db ("xyz") or die(mysql_error ());

    $sql = "SELECT Pic FROM zxd WHERE ID='".$_GET['Id']."'";
    //'".$_GET['Id']."'";

    $result = mysql_query("$s ql") or die("Invalid query: " . mysql_error());

    header("Content-type: image/jpeg");
    $test=mysql_res ult($result,0);

    $desired_width = 85;
    $desired_height = 110;

    $im = imagecreatefrom string($test);
    $new = imagecreatetrue color($desired_ width, $desired_height );

    $x = imagesx($im);
    $y = imagesy($im);

    imagecopyresamp led($new, $im, 0, 0, 0, 0, $desired_width, $desired_height , $x, $y);

    imagedestroy($i m);
    header("cache-Control: no-cache, must-revalidate"); // HTTP/1.1
    header("Expires : Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    header('Content-type: image/jpeg');
    imagejpeg($new, NULL, 85);

    imagedestroy($n ew);
    // echo $test;

    mysql_close($li nk);
    ?>
    [/PHP]
  • pradeepjain
    Contributor
    • Jul 2007
    • 563

    #2
    or is there a way to make it a pdf and mail it on a click of a button

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, Pradeep.

      Attaching images is much easier with PHPMailer or SwiftMailer (http://www.ustrem.org/bg/articles/se...-phpmailer-en/).

      Comment

      Working...