tournasdim
6/25/2013 - 7:38 AM

Sending mail without attachment using the PHPMailer Class

Sending mail without attachment using the PHPMailer Class

<?php

/*
First downlaod the library from Google 
http://code.google.com/a/apache-extras.org/p/phpmailer/

*/
require_once 'class.phpmailer.php';
$mail = new PHPMailer(true); 
$to = "sendmailto@gmail.com";
$subject = "this is a test from phpmailer" ;
$message = "This message was send with the PHP-mailer library and uses the defauld (mail) ";
try { 
$mail->AddAddress($to, 'Example To');
$mail->SetFrom('testexample@example.com', 'Example');
$mail->AddReplyTo('example@example.com', 'Example');
$mail->Subject = $subject;
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML($message);
$mail->Send();
echo "<p><br>Message Sent OK</br></p>";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}