RSS

Sending Email through PHP scripts

Wed, Jul 9, 2008

Featured, PHP

Most Linux hosting doesn’t allow direct mail sending through PHP mail() function due to spam security issue. In order to send email through PHP mail() function, you need to be authenticate first by the SMTP server. Simplest way to do is to use the PHPMailer. Below is the sampleĀ  php code using PHPMailer.

<?php

include(”class.phpmailer.php”);
$mail = new PHPMailer();
$mail-> IsSMTP();
$mail->Host = “mail.yourdomain.com”;
$mail->SMTPAuth = true;
$mail->Username = “youruseremail@yourdomain.com”;
$mail->Password = “yourpassword”;
$mail->From = “youremail@yourdomain.com”;
$mail->FromName = “YourName”;
$mail->AddAddress($To-EmailAddress);
$mail->AddReplyTo(”youremail@yourdomain.com”, “YourName”);
$mail->IsHTML(true);
$mail->Subject = “subject is here”;
$mail->Body = “full body message here”;
$mail->AltBody = “full body message same here”;

if(!$mail->Send())
{
$Confirm = “Error in sending! Message hasn’t been sent”;
}
else
{
$Confirm = “Message has been sent”;
}
?>

, , ,

3 Comments For This Post

  1. ctrl-c Says:

    thanks for this tutorial, it has helped me a lot

  2. Daniel Says:

    Does this mean I can’t send mails anymore through PHP with my Linux Minipack Hosting account?

  3. Root Says:

    Hi Daniel, this articles explains how to send email PHP through Linux hosting

Leave a Reply