php send email with attachment

后端 未结 5 1322
执念已碎
执念已碎 2020-12-02 19:36

How to send the email with resume attachment ,

i take snippet from this place Click here

In this site, snippet works fine,

Even i got the mail, but

5条回答
  •  渐次进展
    2020-12-02 19:58

    Your best bet is to use the Mime Mail PEAR library for handling attachments. It's much easier and cleaner and you'll be less prone to errors.

    PEAR Mime Mail

    You can attach files to an email simply like this:

    $headers['From'] = 'from@domain.com';
    $headers['To'] = 'to@domain.com';
    $headers['Subject'] = 'Email Subject';
    
    $mime = new Mail_mime("\r\n");
    $mime->setTXTBody('Email text');
    $mime->addAttachment($filedata, 'application/octet-stream', 'filename', true, 'base64');
    
    //Prepare the message to be sent
    $body = $mime->get();
    $headers = $mime->headers($headers);
    
    //Send the message via SMTP
    $mail_obj =& Mail::factory('smtp', array('host' => 'mail.domain.com', 'port' => 25));
    $mail_obj->send($to, $headers, $body);
    

提交回复
热议问题