File attachment in php mail function.

Discussion in 'PHP' started by Talker, Mar 3, 2008.

  1. #1
    Hi,

    I have to send out an email with an attachment using the php mail() function.
    I have been able to script the mailing using only txt/html.

    
    $to = $emailaddress;
    $subject = "Confirmation of message receipt";
    $message = $NewBody;
    // Always set content-type when sending HTML email
        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
    // More headers
        $headers .= 'From: webmaster <validemaill@domain.com>' . "\r\n";
            
        mail($to,$subject,$message,$headers);
    
    
    PHP:
    $Newbody is a string (html formatted).
    I have the file path in another string.. $filepath

    Can somebody out there please help me accomplish this small task?
    I require the html formatting as well as the file to be attached with the email.

    Talker.
     
    Talker, Mar 3, 2008 IP
  2. m0nkeymafia

    m0nkeymafia Well-Known Member

    Messages:
    399
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    125
    #2
    Try looking at PHP Mailer, its free and can do what you want and more
     
    m0nkeymafia, Mar 3, 2008 IP
    Talker likes this.
  3. Talker

    Talker Notable Member

    Messages:
    2,795
    Likes Received:
    108
    Best Answers:
    0
    Trophy Points:
    210
    #3
    Thanks, i guess its hard to accomplish my requirements with the normal php mail function. I will take a look at phpmailer.
     
    Talker, Mar 3, 2008 IP
  4. Talker

    Talker Notable Member

    Messages:
    2,795
    Likes Received:
    108
    Best Answers:
    0
    Trophy Points:
    210
    #4
    Thank a lot monkeymafia. PHPMailer did the job !! Rep added because you helped me where i was stuck.
     
    Talker, Mar 5, 2008 IP