Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Thursday, July 28, 2016

Error connecting external SMTP server

Here I am with some quick solution, if you are sending email connecting to external smtp server like smtp.gmail.com you may have to consider to check 2 options.

1. Check smtp ports are open or make sure its not block:
Open your WHM and go to "ConfigServer Security & Firewall" and Edit the configuration file for the csf firewall and lfd or click on "Firewall Configuration" locate SMTP_PORTS and make sure porst are open (Ex: 25,465,587)

2. Check smtp allowed users are added in the list or Always allow the following comma separated users and groups to bypass SMTP_BLOCK
Open your WHM and go to "ConfigServer Security & Firewall" and Edit the configuration file for the csf firewall and lfd or click on "Firewall Configuration" locate SMTP_ALLOWUSER and add the cpanel username (Ex: cpanel, )

Save the changes & you restart both csf and lfd.

In anyway if this one helps you, please make a comment & share in your post

Thank you.
Saf

UPDATE:
This is really strange, new problem rise everyday and we have to find solution, codes are also same like life now.

“Password not accepted from server: 535 Incorrect authentication data” when sending with GMail and phpMailer

using CentOs 6 Login to CPanel > Tweak Settings > All> "Restrict outgoing SMTP to root, exim, and mailman (FKA SMTP Tweak)" <== disable it.

Reference:  http://stackoverflow.com/questions/14297264/password-not-accepted-from-server-535-incorrect-authentication-data-when-send

Thursday, November 7, 2013

How to read folder names/ file names in PHP

1. How to read folder name in PHP

$folderpath = "./FOLDER-NAME/*";

foreach(glob($folderpath, GLOB_ONLYDIR) as $foldername){

/* Do your magic here */

echo $foldername;

}
Don't forget to add '/*' after your folder name
2. How to read file names in a folder in PHP

$folderpath = "./FOLDER-NAME/*.*";

foreach(glob($folderpath) as $filename){

/* Do your magic here */

echo $filename;

}
Don't forget to add '/*.*' after your folder name

Might you will complain that it is reading the whole path, not the folder/ filename you want to get at the end. So follow this trick. :)

$folderpath = "./FOLDER-NAME/*";

foreach(glob($folderpath, GLOB_ONLYDIR) as $foldername){

$newFolderName = str_replace("./FOLDER-NAME/", '', $foldername);

echo $newFolderName;

}
TaDa !!!!

Tuesday, November 5, 2013

How to use the same MySQL query again and again

Actually, what we going to do is to move the internal row pointer to re-query. For this, Im going to use the mysql function mysql_data_seek().


The internal row pointer is the current row position in a result returned by the mysql_query() function.

$sql    = "SELECT * FROM tbl_data";
$result = mysql_query($sql,$con);

while ($row = mysql_fetch_array($result)) {
   /* Show your data here*/
}

/* Call the result info again*/

mysql_data_seek($result,0); 

//  you can change the 0 into any number. From this, it will control from which row number you want to start the query again.

while ($row = mysql_fetch_array($result)) {
   /* Show your data for the 2nd time */
}

Monday, May 13, 2013

Getting the first letters of text using PHP [SafGetFirstLetters]

It is always better to make small small functions and keep a library, I was collecting all my experimental functions since I am in to PHP.

I wanted to take first letters from a line of text and realized that I have to use this for many places. Yesterday I have made a new one "SafGetFirstLetters"?

What does it do?
Example Text: This Is A Example Text Line
Output: TTIAETL

SafGetFirstLetters("Lagoon Water Villa with Private Pool", 5)
will return: "LWVwP"
5 is the limit of the text I have asked from function to return.

function SafGetFirstLetters($Text,$MaxChr){
 $TextArray = explode(" ",$Text);
 $WordCount = count($TextArray);
 if ($WordCount) {
  $MakeText='';
  for ($i_a = 0; $i_a < $WordCount; $i_a++) {
   $MakeText = $MakeText . substr($TextArray[$i_a],0,1);
  }
 }
 if ($MaxChr) {
  return substr($MakeText,0,$MaxChr);
 }else{
  return $MakeText;
 }
}
If you like it please comment.
Thanks.
Safras Ahamed

Tuesday, March 26, 2013

How Get Number of Days in a Month in PHP

Extracted from PHP.net

function days_in_month($month, $year)  { 
return $month == 2 ? 
($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : 
(($month - 1) % 7 % 2 ? 30 : 31); 
}

echo days_in_month(YOUR_MONTH,YOUR_YEAR);


More Simple way by a SafFunction

function days_in_month($month,$year) {
return date('t',mktime(0,0,0,$month,1,$year));
}

echo days_in_month(YOUR_MONTH,YOUR_YEAR);

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)

Friday, March 22, 2013

PHP Date Functions with SafDate Functions

This is a set of small functions I use, this will make my life easy, no need to remember all the variables at date() function and you can make some predefined functions that you use always.













saf.date.functions.php
<?php
//Pass 2007-01-22 as date and output  as January 22, 2007
function SafDate1V2($date){
    list($y,$m,$d) = explode("-",$date);
    $mycooldate = date("F d, Y",mktime(0, 0, 0, $m, $d, $y));
    return $mycooldate;
}
//Pass 2007-01-22 as date and output  as Jan 22, 2007
function SafDate2V2($date){
    list($y,$m,$d) = explode("-",$date);
    $mycooldate = date("M d, Y",mktime(0, 0, 0, $m, $d, $y));
    return $mycooldate;

}
//Pass 2007-01-22 as date and output  as Jan 22, 07
function SafDate3V2($date){
    list($y,$m,$d) = explode("-",$date);
    $mycooldate = date("M d, y",mktime(0, 0, 0, $m, $d, $y));
    return $mycooldate;
}
//Pass 2007-01-22 as date and output as Sunday Jan 22, 2007
function SafDate4V2($date){
    list($y,$m,$d) = explode("-",$date);
    $mycooldate = date("l M d, Y",mktime(0, 0, 0, $m, $d, $y));
    return $mycooldate;
}
?>
<?php
//Pass 2007-01-22 as date and output as Sun, Jan 22, 2007
function SafDate5V2($date){
    list($y,$m,$d) = explode("-",$date);
    $mycooldate = @date("D, M d, Y",mktime(0, 0, 0, $m, $d, $y));
    return $mycooldate;
}
?>