sending html email with images using mail()

Discussion in 'PHP' started by cris02, Nov 16, 2009.

  1. #1
    Hello, just trying to send html email format but i have a problem the html text display correct but i can't see the images. please fix my code:
    
    $to = "receiver1@yahoo.com, receiver2@ymail.com, receiver3@gmail.com";
    $from = "sender@domain.com";
    $subject = "Hello! This is HTML email";
    $ms=$_POST['textarea'];
    
    $message =  $ms;
    
    $headers = "MIME-Version: 1.0\r\n";
    $headers  = "From: $from\r\n";
    $headers .= "Content-type: text/html\r\n";
    
        
    mail($to, $subject, $message, $headers);
    
    PHP:
    while $_POST[textarea] is the html message that contains <img src= "http://mydomain.com/myimage.jpg" width="100" height="100" alt=""><br><p>This is a test</p><img src="http//mydomain.com/my2ndimg.jp">

    Please help. Thanks
     
    cris02, Nov 16, 2009 IP
  2. vinpkl

    vinpkl Active Member

    Messages:
    899
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    58
    #2
    hi

    i think you can view images in email message that are already stored on your server.

    If you are trying to upload the image and then at the same time sending it via email then you need to send it as attachment.

    i dont see any code related to attachment.

    if the image is already on your server then try replacing this

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

    or you can check that the email is shooted after the image gets uploaded.

    vineet
     
    Last edited: Nov 17, 2009
    vinpkl, Nov 17, 2009 IP
  3. cris02

    cris02 Member

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    Yes its in the server... Thanks, I've solve the problem now just placing this is to put trailing slashes inside the <img src="">

    $message =  preg_replace('/\\\\/','', $ms);
    PHP:
    Thanks.
     
    cris02, Nov 17, 2009 IP