LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-16-2007, 11:28 AM   #1
malonesam
LQ Newbie
 
Registered: May 2007
Posts: 1

Rep: Reputation: 0
Linux and PHP mail() funtion


Hi:

I have been reading several docs on security issues with Linux/PHP. This site gave me some more pointers. I was wondering if I can get help in my PHP coding ....

I have a site where people could sign up for membership. After someone fills up the form on the sign up page and submits it, an email with the filled in info, is sent to me so that I can approve and activate the person after running some credential checks. As soon as I activate the person, an email is automatically sent to the user so that they can start loging in... the usual method found in most sites.

My website host has disabled my PHP mail() function and I have not been able to get a straight answer for 3 weeks, and now they have come back with a short, cryptic note saying that PHP suexec has been turned on and "I have to provide my user id in PHP coding" and then the PHP mail() function will work.

I am not sure where or how to do that - I mean, provide my user id in the PHP code. I can post the code here, if someone can help me..?

 
Old 05-17-2007, 09:53 AM   #2
zaichik
Member
 
Registered: May 2004
Location: Iowa USA
Distribution: CentOS
Posts: 419

Rep: Reputation: 30
I found this mail function at http://us2.php.net/mail, perhaps it will help point you in the correct direction.

Code:
function mymail($to,$subject,$message,$headers)
{

  // set as global variable
  global $GLOBAL;
  
  // get From address
  if ( preg_match("/From:.*?[A-Za-z0-9\._%-]+\@[A-Za-z0-9\._%-]+.*/", $headers, $froms) ) {
      preg_match("/[A-Za-z0-9\._%-]+\@[A-Za-z0-9\._%-]+/", $froms[0], $fromarr);
      $from = $fromarr[0];
  }

  // Open an SMTP connection
  $cp = fsockopen ($GLOBAL["SMTP_SERVER"], $GLOBAL["SMTP_PORT"], &$errno, &$errstr, 1);
  if (!$cp)
   return "Failed to even make a connection";
  $res=fgets($cp,256);
  if(substr($res,0,3) != "220") return "Failed to connect";

  // Say hello...
  fputs($cp, "HELO ".$GLOBAL["SMTP_SERVER"]."\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "250") return "Failed to Introduce";
  
  // perform authentication
  fputs($cp, "auth login\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "334") return "Failed to Initiate Authentication";
  
  fputs($cp, base64_encode($GLOBAL["SMTP_USERNAME"])."\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "334") return "Failed to Provide Username for Authentication";
  
  fputs($cp, base64_encode($GLOBAL["SMTP_PASSWORD"])."\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "235") return "Failed to Authenticate";

  // Mail from...
  fputs($cp, "MAIL FROM: <$from>\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "250") return "MAIL FROM failed";

  // Rcpt to...
  fputs($cp, "RCPT TO: <$to>\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "250") return "RCPT TO failed";

  // Data...
  fputs($cp, "DATA\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "354") return "DATA failed";

  // Send To:, From:, Subject:, other headers, blank line, message, and finish
  // with a period on its own line (for end of message)
  fputs($cp, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "250") return "Message Body Failed";

  // ...And time to quit...
  fputs($cp,"QUIT\r\n");
  $res=fgets($cp,256);
  if(substr($res,0,3) != "221") return "QUIT failed";

  return true;
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Iptables and Mail funtion novice06 Linux - Security 9 03-23-2006 03:48 AM
php mail() funtion in chrooted Apache clau_bolson Linux - Software 0 12-06-2005 10:02 AM
Cannot send mail with mail() command in PHP 4.3.4, Apache 2.0.48, Mandrake Linux 10 arcanum Linux - General 3 06-27-2004 06:06 PM
anyone know howto create e-mail portal using Linux and PHP khaimun LQ Suggestions & Feedback 0 03-06-2001 02:35 PM


All times are GMT -5. The time now is 02:09 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration