Sunday, March 24, 2013

SafSendMailV2: A function to send mail using php

I started to make and collect my own function since 2001 and SafSendMail I made it in 2002 for a project where there was lots of mail sending option. If I want to send a mail I have to write whole lot and I didn't like it. Created SafSendMail so that I can send mail as I want using a single line.

Later I made SafSendMailV2 supporting HTML and other stuff as you can see, if any mail sent using V2 it will also record From-IP & From-File. Using this you can Identify different things.




function SafSendMailV2(
 $MYRECIPIENTE_EMAIL,
 $MYRECIPIENTE_NAME,
 $MYFROM_NAME,
 $MYFROM_EMAIL,
 $MYSUBJECT,
 $MYBODY,
 $MYHTML,
 $REMOTE_ADDR,
 $PHP_SELF){
 $MYRECIPIENTE_EMAIL  = "$MYRECIPIENTE_EMAIL";
 if ($MYHTML==true) {
  $MYHEADERS = "From: $MYFROM_NAME <$MYFROM_EMAIL>\r\n";
  $MYHEADERS .= "MIME-Version: 1.0\r\n";
  $MYHEADERS .= "Content-Type: text/html; charset=windows-1256\r\n";
  $MYHEADERS .= "Content-Transfer-Encoding: base64\r\n";
  $MYHEADERS .= "From-IP: $REMOTE_ADDR\r\n";
  $MYHEADERS .= "From-File: $PHP_SELF\r\n";
  $MYHEADERS .= chunk_split(base64_encode("$MYBODY"));
  mail("$MYRECIPIENTE_EMAIL", "$MYSUBJECT", "", $MYHEADERS);
 }else{
  $MYHEADERS = "From: $MYFROM_NAME <$MYFROM_EMAIL>\r\n";
  $MYHEADERS .= "From-IP: $REMOTE_ADDR\r\n";
  $MYHEADERS .= "From-File: $PHP_SELF";
  mail("$MYRECIPIENTE_EMAIL", "$MYSUBJECT", "$MYBODY", $MYHEADERS);
 }
}

How to use?
SafSendMailV2("Recipiente@domain.com","Recipiente Name","Your Name","Your Email","Subject",$MYBODY,true,$REMOTE_ADDR,$PHP_SELF)

2 comments:

  1. Replies
    1. Shiran, Thank you for your comment,
      It made me feel "Thawa Daanna!"
      So I will post more and more

      Delete