Wie zum senden von E-Mails mit PHP mit dem PEAR Mail package mit Anhang

Ich bin versucht, senden Sie eine E-Mail mit PHP mit dem PEAR mail package mit einem Anhang. Die E-Mail sendet erfolgreich mit einem code habe ich aus dem internet. Jedoch, die Anlage nicht gesendet werden oder befestigt werden. Wo bin ich, was falsch läuft, unten ist mein code.

<?php

require_once "Mail.php"; 
require_once "Mail/mime.php";

$from = "<[email protected]>";
$to = "<[email protected]>";
$subject = "Testing email from PHP with attachment";
$body = "Testing email from PHP with attachment";
$file = "invoices/PRINV7_3.pdf";
$host = "host";
$port = "25";
$username = "username";
$password = "password";

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

$mime = new Mail_mime();

if ($mime->addAttachment($file,'application/pdf')){
    echo "attached successfully! </br>";
} else {
    echo "Nope, failed to attache!! </br>";
}

$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'port' => $port,
    '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>");
 }

?>
Wo sehen Sie hinzufügen, $mime, die E-mail-Nachricht?
Das ist alles was ich habe, wenn es muss Hinzugefügt werden, dann wo muss ich es hinzufügen.

InformationsquelleAutor Richard Tonata | 2012-08-03

Schreibe einen Kommentar