• Welcome to Web Hosting Community Forum for Webmasters - Web hosting Forum.
 

Recommended Providers

Fully Managed WordPress Hosting
lc_banner_leadgen_3
Fully Managed WordPress Hosting

WordPress Theme

Divi WordPress Theme
WPZOOM

Forum Membership

Forum Membership

send mail using SMTP authentication :: phpmailer script

Started by Kailash, February 04, 2007, 01:42:44 PM

Kailash

Hi,

Now a day, most of the hosting providers disable nobody user on their server or do not allow to send mail through script without SMTP authentication to stop the spamming from their servers. In such cases, you have to use SMTP authentication to send mail through PHP, ASP, or ASP.Net script. Below is the sample SMTP authentication script to send mail through PHP script:

<?php
require("class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP();                                // send via SMTP
$mail->Host     = "smtp.domain.com"; // SMTP servers
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = "[email protected]";   // SMTP username
$mail->Password = "password"; // SMTP password

$mail->From     = "[email protected]";
$mail->FromName = "Name";
$mail->AddAddress("[email protected]","Name");
$mail->AddReplyTo("[email protected]","Your Name");

$mail->WordWrap = 50;                              // set word wrap

$mail->IsHTML(true);                               // send as HTML

$mail->Subject  =  "Here is the subject";
$mail->Body     =  "This is the <b>HTML body</b>";
$mail->AltBody  =  "This is the text-only body";

if(!$mail->Send())
{
   echo "Message was not sent <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";

?>

Note: To use above script, PHPMailer must be installed on the server. For more information, go to https://github.com/PHPMailer/PHPMailer

Thanks,