SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sending an email from local host with file atachment HELP needed

    Hi i am new to PHP scripts but am learning fast.

    I have apache, PHP and pear installed and am trying to send an email with a .jpg file attatched.

    I have just about managed to do this with a lot of searching on the net.

    If i send from email1@*****.com to email2@yahoo.com via the PHP code then no picture is displayed, it is a blank thumbnail.
    but the image can be downlaoded.


    If i send from email1@*****.com to email2@yahoo.com via outlook, then the picture is displayed in the receiving mail.

    Confusing the H*** out of me.

    WHY IS THIS HAPPENING ???

    Can anyone solve this problem. Here is the code I found to use. THANK YOU.


    Using Pear mail.php and mime.php

    PHP Code:
    <?php
    require_once "c:/php/pear/mail/Mail.php"; // PEAR Mail package
    require_once ('c:/php/pear/mime/mime.php'); // PEAR Mail_Mime packge

    $from = "info@*******.com";
    $to = "example@yahoo.com";
    $subject = 'Picture from info@******.com';

    $headers = array ('From' => $from,'To' => $to, 'Subject' => $subject);

    $text = 'Text version of email';// text and html versions of email.
    //$html = '<html><body>HTML version of email. <strong>This should be bold</strong></body></html>';

    $file = 'C:/pics/testpic1.jpg'; // attachment
    $crlf = "\n";
    $mime = new Mail_mime($crlf);
    $mime->setTXTBody($text);
    $mime->setHTMLBody($html);
    $mime->addAttachment($file, 'text/plain');

    //do not ever try to call these lines in reverse order
    $body = $mime->get();
    $headers = $mime->headers($headers);

    //Smtp email authentication

    $host = "mail.*******.com";
    $username = "info@*******.com";
    $password = "**********";

    $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true,
    'username' => $username,'password' => $password));

    $mail = $smtp->send($to, $headers, $body);

    if (PEAR::isError($mail)) {
    echo("<p>" . $mail->getMessage() . "</p>");
    }
    else {
    echo("<p>Message successfully sent!</p>");
    }
    ?>

  2. #2
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SOLVED.

    Change 1 line and pictures are now being displayed in email

    $mime->addAttachment($file, 'image/jpeg');


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •