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     = "mail.yourdomain.com"; // SMTP server
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = "you@yourdomain.com";  // SMTP username
$mail->Password = "youremailpassword"; // SMTP password
$mail->From     = "you@yourdomain.com";
$mail->FromName = "Your Name";
$mail->AddAddress("somebody@somedomain.com","Somebody name");
$mail->AddReplyTo("You@yourdomain.com","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";
if(!$mail->Send())
{
echo "Message was not sent

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

Was this answer helpful?

 Print this Article

Also Read

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...

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...