home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
66-211-214-51.static.velocity.net
/
66-211-214-51.static.velocity.net.tar
/
66-211-214-51.static.velocity.net
/
OPMail
/
pearMail.php
< prev
next >
Wrap
PHP Script
|
2011-03-07
|
2KB
|
73 lines
<?php
require_once "Mail.php"; // PEAR Mail package
require_once ('Mail/mime.php'); // PEAR Mail_Mime packge
$myFile = "MailData.txt"; //file to read from
$fh = fopen($myFile, 'r'); //open file for reading
$host = trim(fgets($fh)); //gets email server
$port = trim(fgets($fh)); //gets email server port
$username = trim(fgets($fh)); //gets user name for email
$password = trim(fgets($fh)); //gets password for email
$from = trim(fgets($fh)); //gets FROM
$to = trim(fgets($fh)); //gets TO
$subject = trim(fgets($fh)); //gets SUBJECT
$attachmentName = trim(fgets($fh)); //gets ATTACHMENT NAME
$attachPath = trim(fgets($fh)); //gets PATH TO ATTACHMENT
$body = "";
while(!feof($fh))
{
$body .= fgets($fh);
}
fclose($fh); //Close the File
$attachmentFull = "";
$attachmentFull .= $attachPath;
$attachmentFull .= $attachmentName;
//Local Testing variables
/*
$host = "smtp.aol.com"; //gets email server
$port = 587; //gets email server port
$username = 'mateomarriotti'; //gets user name for email
$password = 'gunho'; //gets password for email
$from = "Matt <mateomarriotti@aol.com>"; //gets FROM
$to = "Matt <mateomarriotti@aol.com>"; //gets TO
$subject ='Test mime message with an attachment'; //gets SUBJECT
$attachmentName = 'sample.txt'; // attachment
$attachPath = "./"; //gets PATH TO ATTACHMENT
$body = "This is a test body for the email";
*/
$headers = array ('From' => $from,'To' => $to, 'Subject' => $subject);
$text = $body;// text and html versions of email.
$html = $body;
//$html = '<html><body>HTML version of email. <strong>This should be bold</strong></body></html>';
$crlf = "\n";
$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
//$mime->addAttachment($attachmentName, 'text/plain');
$mime->addAttachment($attachmentFull, 'text/plain');
//do not ever try to call these lines in reverse order
$body = $mime->get();
$headers = $mime->headers($headers);
$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>");
}
?>