function sendMail($props) { $mail = new PHPMailerLite(); // defaults to using php "Sendmail" (or Qmail, depending on availability) $mail->IsMail(); // telling the class to use native PHP mail() try { $mail->SetFrom('*****@*****.**', 'Adei User'); $mail->AddAddress($props['email'], 'User'); $mail->Subject = 'Adei Graph'; $mail->MsgHTML($props['message']); $mail->AddAttachment($props['attachement']); // attachment $mail->Send(); return $props['message']; } catch (phpmailerException $e) { return 'phpmailerException'; //$e->errorMessage(); //Pretty error messages from PHPMailer } catch (Exception $e) { return 'exception'; //$e->getMessage();//Boring error messages from anything else! } }
<body> <?php require_once '../class.phpmailer-lite.php'; $mail = new PHPMailerLite(true); // the true param means it will throw exceptions on errors, which we need to catch $mail->IsSendmail(); // telling the class to use SendMail transport try { $mail->SetFrom('*****@*****.**', 'First Last'); $mail->AddAddress('*****@*****.**', 'John Doe'); $mail->Subject = 'PHPMailer Test Subject via mail(), advanced'; $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically $mail->MsgHTML(file_get_contents('contents.html')); $mail->AddAttachment('images/phpmailer.gif'); // attachment $mail->AddAttachment('images/phpmailer_mini.gif'); // attachment $mail->Send(); echo "Message Sent OK</p>\n"; } catch (phpmailerException $e) { echo $e->errorMessage(); //Pretty error messages from PHPMailer } catch (Exception $e) { echo $e->getMessage(); //Boring error messages from anything else! } ?> </body>
<title>PHPMailer - Sendmail basic test</title> </head> <body> <?php require_once '../class.phpmailer-lite.php'; $mail = new PHPMailerLite(); // defaults to using php "Sendmail" (or Qmail, depending on availability) $body = file_get_contents('contents.html'); $body = eregi_replace("[\\]", '', $body); $mail->SetFrom('*****@*****.**', 'First Last'); $address = "*****@*****.**"; $mail->AddAddress($address, "John Doe"); $mail->Subject = "PHPMailer Test Subject via Sendmail, basic"; $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->MsgHTML($body); $mail->AddAttachment("images/phpmailer.gif"); // attachment $mail->AddAttachment("images/phpmailer_mini.gif"); // attachment if (!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message sent!"; } ?> </body> </html>