Pages

Friday, July 4, 2014

Send Emali with SSMTP

install ssmtp :

sudo apt-get install ssmtp


Edit file  ssmtp.conf
sudo vim /etc/ssmtp/ssmtp.conf

edit seperti dibawah ini :

# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
#root=postmaster
root=test@gmail.com

# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
#mailhub=mail
mailhub=smtp.gmail.com:587
AuthUser=test@gmail.com
AuthPass=xxxxxxxx
UseTLS=YES
UseSTARTTLS=YES

# Where will the mail seem to come from?
#rewriteDomain=

# The full hostname
hostname=test@gmail.com

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES



on php file :



//create fuction for send email

   function sendmail ($cc,$to,$sb,$msg)
    {       

    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= "From: aem@aem.co.id \r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'cc:'.$cc. "\r\n";
    $headers .= 'Bcc:aem@aem.co.id'. "\r\n";
    ini_set("SMTP","smtp.aem.co.id");
    ini_set("sendmail_from",$mailfrom); 
    mail($to,$sb, $msg, $headers);
    //return $true;           
       
    }   


//send mail

$from: "xxx@xxx.com";
$mailto: "xxx@xxx.com";
$subject: "testing send email";
$message: "Test";

sendmail($from,$mailto,$subject,$message);