Sample Code : Sending mail via PHP

You can use PHPMailer to send mails via PHP. To use this open source object you need to download two php class files which can be found here  and upload them into your project include folder first.

Here's a complex example of sending an HTML email with SMTP authentication and attachments

$mail = new PHPMailer();
$mail->IsSMTP();                                   // send via SMTP
$mail->Host     = ""; // SMTP server
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = "";  // SMTP username
$mail->Password = "youremailpassword"; // SMTP password
$mail->From     = "";
$mail->FromName = "Your Name";
$mail->AddAddress("","Somebody name");
$mail->AddReplyTo("","Your Name");
$mail->WordWrap = 50;                              // set word wrap
$mail->AddAttachment("Path to Attachment ");      // attachment
$mail->IsHTML(true);                               // send as HTML
$mail->Subject  =  "Here is the subject";
$mail->Body     =  "This is the HTML body";
$mail->AltBody  =  "This is the text-only body";
echo "Message was not sent

echo "Mailer Error: " . $mail->ErrorInfo;
echo "Message has been sent";

Was this answer helpful?

 Print this Article

Also Read

I get this error when trying load my PHP page : "FATAL ERROR: register_globals is disabled in php.ini, please enable it!"

Register_Globals directive is set to OFF because of potential security issues.  PHP has this...

Sample Code : Query MySQL Database in PHP

<html><head><title>MySQL Test...

What is the path to Perl on the Servers?

The path is : #!/usr/bin/perl However! This is not require on the Windows platform, it is a Unix...