"php: how to send email with attachment using smtp settings?" Code Answer

5

found this code as one of the first hits of the google://pear mail attachment search.

include('mail.php');
include('mail/mime.php');

$text = 'text version of email';
$html = '<html><body>html version of email</body></html>';
$file = './files/example.zip';
$hdrs = array(
              'from'    => 'someone@domain.pl',
              'to'      => 'someone@domain.pl',
              'subject' => 'test mime message'
              );

$mime = new mail_mime();

$mime->settxtbody($text);
$mime->sethtmlbody($html);

$mime->addattachment($file,'application/octet-stream');

$body = $mime->get();
$hdrs = $mime->headers($hdrs);

$mail =& mail::factory('mail', $params);
$mail->send('mail@domain.pl', $hdrs, $body); 
By chris_techno25 on May 31 2022

Answers related to “php: how to send email with attachment using smtp settings?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.