» Host multiple domains in one plan
» Manage all your domains in one control panel
» Both Windows and Linux Options
» Windows Plans starting at .95 per month
» Linux Plans starting at .95 per month
» Windows Plan: MS SQL 2005 Database Included
 
Window Plans   Linux Plans
 
Close  
Accu Web Hosting Accu Web Hosting Accuweb Hosting
Accu Web Hosting Accu Web Hosting Window Hosting Home Accu Web Hosting Window Hosting Accu Web Hosting PHP Hosting Accu Web Hosting Reseller Accu Web Hosting SQL Hosting Accu Web Hosting   accu web hosting
 

Go Back   Web Hosting Technical Support Discussion Forum > General Web Hosting Discussion Forum and Support > Linux Web Hosting Discussion Forum and Support

Linux Web Hosting Discussion Forum and Support Discussion forum on Linux Web Hosting issues related to cpanel, whm, ensim, plesk, emails, ftp, frontpage, php, perl, cgi or permission.

Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old 08-30-2005
Member
 
Join Date: Aug 2004
Posts: 65
Rep Power: 0
Vaughn is on a distinguished road
Send a message via MSN to Vaughn Send a message via Yahoo to Vaughn
Default

Hello Everyone,

We have disabled php mail() function on the server due to several reasons.

To begin with, it is a major cause of spamming. Next, since it uses the 'nobody' user to send mails, it creates problems of email spoofing.

Thus, scripts utilizing the 'nobody' user to not be able to send mails now. The best alternative to this is to use SMTP authentication. If you are one of those users who need this code then kindly find it as below:

Code:
<?php
//new function

$to = "post@example.com";
$nameto = "Who To";
$from = "post@example.com";
$namefrom = "Who From";
$subject = "Hello World Again!";
$message = "World, Hello!";
authSendEmail($from, $namefrom, $to, $nameto, $subject, $message);
?>


<?php
/* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */ 

//Authenticate Send - 21st March 2005
//This will send an email using auth smtp and output a log array
//logArray - connection, 

function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message)
{
 Â* Â*//SMTP + SERVER DETAILS
 Â* Â*/* * * * CONFIGURATION START * * * */
 Â* Â*$smtpServer = "mail.server.com";
 Â* Â*$port = "25";
 Â* Â*$timeout = "30";
 Â* Â*$username = "smtpusername";
 Â* Â*$password = "smtppassword";
 Â* Â*$localhost = "localhost";
 Â* Â*$newLine = "\r\n";
 Â* Â*/* * * * CONFIGURATION END * * * * */
 Â* Â*
 Â* Â*//Connect to the host on the specified port
 Â* Â*$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
 Â* Â*$smtpResponse = fgets($smtpConnect, 515);
 Â* Â*if(empty($smtpConnect)) 
 Â* Â*{
 Â* Â* Â* Â*$output = "Failed to connect: $smtpResponse";
 Â* Â* Â* Â*return $output;
 Â* Â*}
 Â* Â*else
 Â* Â*{
 Â* Â* Â* Â*$logArray['connection'] = "Connected: $smtpResponse";
 Â* Â*}

 Â* Â*//Request Auth Login
 Â* Â*fputs($smtpConnect,"AUTH LOGIN" . $newLine);
 Â* Â*$smtpResponse = fgets($smtpConnect, 515);
 Â* Â*$logArray['authrequest'] = "$smtpResponse";
 Â* Â*
 Â* Â*//Send username
 Â* Â*fputs($smtpConnect, base64_encode($username) . $newLine);
 Â* Â*$smtpResponse = fgets($smtpConnect, 515);
 Â* Â*$logArray['authusername'] = "$smtpResponse";
 Â* Â*
 Â* Â*//Send password
 Â* Â*fputs($smtpConnect, base64_encode($password) . $newLine);
 Â* Â*$smtpResponse = fgets($smtpConnect, 515);
 Â* Â*$logArray['authpassword'] = "$smtpResponse";

 Â* Â*//Say Hello to SMTP
 Â* Â*fputs($smtpConnect, "HELO $localhost" . $newLine);
 Â* Â*$smtpResponse = fgets($smtpConnect, 515);
 Â* Â*$logArray['heloresponse'] = "$smtpResponse";
 Â* Â*
 Â* Â*//Email From
 Â* Â*fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
 Â* Â*$smtpResponse = fgets($smtpConnect, 515);
 Â* Â*$logArray['mailfromresponse'] = "$smtpResponse";
 Â* Â* Â* Â*
 Â* Â*//Email To
 Â* Â*fputs($smtpConnect, "RCPT TO: $to" . $newLine);
 Â* Â*$smtpResponse = fgets($smtpConnect, 515);
 Â* Â*$logArray['mailtoresponse'] = "$smtpResponse";
 Â* Â*
 Â* Â*//The Email
 Â* Â*fputs($smtpConnect, "DATA" . $newLine);
 Â* Â*$smtpResponse = fgets($smtpConnect, 515);
 Â* Â*$logArray['data1response'] = "$smtpResponse";
 Â* Â*
 Â* Â*//Construct Headers
 Â* Â*$headers Â*= "MIME-Version: 1.0" . $newLine;
 Â* Â*$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
 Â* Â*$headers .= "To: $nameto <$to>" . $newLine;
 Â* Â*$headers .= "From: $namefrom <$from>" . $newLine;
 Â* Â*
 Â* Â*fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$headers\n\n$message\n.\n");
 Â* Â*$smtpResponse = fgets($smtpConnect, 515);
 Â* Â*$logArray['data2response'] = "$smtpResponse";
 Â* Â*
 Â* Â*// Say Bye to SMTP
 Â* Â*fputs($smtpConnect,"QUIT" . $newLine); 
 Â* Â*$smtpResponse = fgets($smtpConnect, 515);
 Â* Â*$logArray['quitresponse'] = "$smtpResponse"; Â* Â*
}
?>
Thanks,
__________________
Vaughn
Team Leader // Tech. Support
AccuWebHosting.Com
email:support@accuwebhosting.com

Blog: blogsandbloggers.com/Vaughn
http://www.accuwebhosting.biz/Vaughn...aughn_Sign.jpg
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-20-2006
Member
 
Join Date: Aug 2004
Posts: 65
Rep Power: 0
Vaughn is on a distinguished road
Send a message via MSN to Vaughn Send a message via Yahoo to Vaughn
Default

You were getting this error as you had an error on line 9, you were missing the semi-colon at the end. I've added it and the error is now fixed, please check.

Thanks,
__________________
Vaughn
Team Leader // Tech. Support
AccuWebHosting.Com
email:support@accuwebhosting.com

Blog: blogsandbloggers.com/Vaughn
http://www.accuwebhosting.biz/Vaughn...aughn_Sign.jpg
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-27-2006
Junior Member
 
Join Date: Oct 2006
Posts: 1
Rep Power: 0
Nimble is on a distinguished road
Default

I found a lot of errors with that authenticated SMTP send function.

For one, it doesn't seem to handle multi-line SMTP server responses, and the mail server certainly seems to be giving them.

So I wrote a small function to handle those:

Code:
function getSmtpResponse($smtpConnection)
{
Â*Â*Â*Â*$smtpResponse = "";
Â*Â*Â*Â*$stmpLine = "";
Â*Â*Â*Â*$getNextLine = true;
Â*Â*Â*Â*while ( $getNextLine )
Â*Â*Â*Â*{
Â*Â*Â*Â*Â*Â*Â*Â*$smtpLine = fgets($smtpConnection);
Â*Â*Â*Â*Â*Â*Â*Â*// If the line has a dash after the response number,
Â*Â*Â*Â*Â*Â*Â*Â*//Â*Â* it's a multiline response
Â*Â*Â*Â*Â*Â*Â*Â*$getNextLine = strpos( $smtpLine, "-" ) == 3;
Â*Â*Â*Â*Â*Â*Â*Â*$smtpResponse .= $smtpLine . "\r\n";
Â*Â*Â*Â*}
Â*Â*Â*Â*return $smtpResponse;
}
...and you replace:

Code:
$smtpResponse = fgets($smtpConnect, 515);
with

Code:
$smtpResponse = getSmtpResponse($smtpConnect);
Also, it seemed to be rejecting outright the AUTH LOGIN. I looked into this, and the order of things sent to the server was wrong. The HELO needs to be an EHLO in order to take this login type, and it needs to be the FIRST thing sent (that is, before the AUTH LOGIN).

How was I finding all this out? I had it split out the contents of the $logArray (in b2evolution, using the debug_die command and a short routine to split apart the array)

I haven't spent the time to figure out how to make it figure out sending errors, but I figure it's probably best to replace this function with something more permanent and less hacky in future.

Hope that helps

-- Ritchie
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Compile php Manuel_ Linux Reseller Accounts Pre-Sales Questions 0 07-10-2006 01:53 AM
How to :: add php extension in windows server Manuel_ Windows Dedicated Servers 0 06-23-2006 07:53 AM
PHP Mail Vaughn Windows Web Hosting Discussion Forum 1 03-27-2006 12:54 AM
Sendmail form for php donjory Windows Web Hosting Discussion Forum 1 02-05-2006 01:48 AM
PHP email facility on site not working anymore Adriaan Linux Web Hosting Discussion Forum and Support 2 08-30-2005 02:02 AM


All times are GMT -5. The time now is 10:16 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC5
http://www.accuwebhosting.com/terms.htm

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32