Matthew Steven Kelly

PHP Email

April5

Are you going to be sending email in PHP? Don’t use the mail() function, unless your site’s email needs are very basic and you are running on a Linux/Unix machine. It is light on features and not built into the Windows version.

The best approach is to use a 3rd party mail program. In the past I have used PHPMailer as it is has all features I have needed. This script is the fix to many SMTP email problems in PHP!

http://sourceforge.net/projects/phpmailer

Below is the PHP code to use it. Place class.phpmailer.php into your php includes directory.

Replace text in << >> with your server information:
http://www.emailaddressmanager.com/tips/mail-settings.html

<?php

require("class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP(); // send via SMTP
$mail->Host = "<<smtpserver>>:<<stmpport>>"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "<<uname>>"; // SMTP username
$mail->Password = "<<pword>>"; // SMTP password
$mail->From = "<<email address from>>";
$mail->FromName = "<<email name from>>";
$mail->AddAddress("<<email address to>>");
$mail->AddReplyTo("<<email address from>>","<<email name from>>");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "Subject";
$mail->Body = "Body text";
$mail->AltBody = $mail->Body;

$mail->Send();

?>

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
posted under Random

Email will not be published

Website example

Your Comment: