Author |
Topic  |
|
Brett Alcock
New Member

65 Posts |
Posted - 01 September 2005 : 11:53:53
|
Modification to use the Unix/Linux sendmail utility in Snitz Forums. Helps virtual server users with providers such as Easily.co.uk that do not support ASP mail objects. These instructions pertain to versions 3.4.02 / 3.4.03 but the principal should be the same for later versions.
The original posting is archived here: http://forum.snitz.com/forum/topic.asp?ARCHIVE=true&TOPIC_ID=34412&SearchTerms=sendmail But due to several requests for help I have posted this revised version. It is functionally the same but the form handler is written in PHP instead of CGI which means one does not have to configure a cgi-bin or specify correct paths and permissions etc which always seemed to be at the root of implementation problems.
Method:
The server script in inc_mail.asp (that normally creates and uses mail objects) is changed to write some html. This html creates a hidden self submitting form, which calls a form handler written in PHP that sends the email.
This works well with v3.4.03 however note that it does depend upon the fact that inc_mail.asp is included once for every email during the creation of any page that sends email, which could of course change in future versions.
Step by Step Instructions:
1. Modify admin_config_email.asp. This allows you to turn on email when there are no supported mail objects found.
On line 201 remove this from the start of the line
if j > UBound(theComponent) then Response.Write(" disabled") else Leaving just thisif lcase(strEmail) <> "0" then Response.Write(" checked") On line 204 remove this from the start of the line
if j > UBound(theComponent) then Response.Write(" checked") else Leaving just this
if lcase(strEmail) = "0" then Response.Write(" checked") 2. Replace the contents of inc_mail.asp with the following script:
<%
MailCount = MailCount + 1
if trim(strFromName) = "" then
strFromName = strForumTitle
end if
Response.Write vbNewLine & _
" <IFRAME id=mail_ifrm" & MailCount & " name=mail_ifrm" & MailCount & " width=0" & vbNewLine & _
" height=0 noresize scrolling=no frameborder=no border=0></IFRAME>" & vbNewLine & _
" <form target=mail_ifrm" & MailCount & vbNewLine & _
" action=""mail.php""" & vbNewLine & _
" method=post id=MailForm" & MailCount & " name=MailForm" & MailCount & "> " & vbNewLine & _
" <input type=hidden name=ToName value=""" & strRecipientsName & """> " & vbNewLine & _
" <input type=hidden name=ToAddr value=""" & strRecipients & """> " & vbNewLine & _
" <input type=hidden name=FromName value=""" & strFromName & """> " & vbNewLine & _
" <input type=hidden name=FromAddr value=""" & strSender & """> " & vbNewLine & _
" <input type=hidden name=Subject value=""" & strSubject & """> " & vbNewLine & _
" <textarea style=""display:none"" name=Content>" & strMessage & "</textarea>" & vbNewLine & _
" <script> " & vbNewLine & _
" MailForm" & MailCount & ".submit(); " & vbNewLine & _
" </script> " & vbNewLine & _
" </form> " & vbNewLine & vbNewLine
%> The MailCount variable is used to ensure multiple inserts are unique and do not conflict with each other. Multiple inserts will occur for example when an administrator approves several members at the same time. You should also add an initialising definition to config.asp at around line 127 just after the others:
Dim MailCount 3. Create mail.php, alter the webmasters address to your own, then place the file in your forum directory. For security reasons the script sends a blind copy of every email to the webmaster. This helps you become aware of any form spoofing attempts, and also gives you a copy of all registration emails which can be very useful when members have sign up problems. Do note though that if you have a large forum with many subscribers you could be inundated with copies. Note; updated 09th September 2005 to use the $_POST superglobals array rather than rely upon the register_globals directive.<?php
function clean($dirty) {
$clean="";
while($clean!=$dirty) { // removes any html tags
$clean=$dirty;
$dirty=preg_replace("/<.*?>/", "", $clean);
}
return $clean;
}
if(isset($_POST)) { // if we have posted data
// clean 'all' posted data incase form spoofed etc
$ToName = clean($_POST['ToName']);
$ToAddr = clean($_POST['ToAddr']);
$FromName = clean($_POST['FromName']);
$FromAddr = clean($_POST['FromAddr']);
$Subject = clean($_POST['Subject']);
$Content = clean($_POST['Content']);
$BccName = 'Webmaster';
$BccAddr = 'webmaster@yoursite.com';
$headers = 'Bcc: '.$BccName.' <'.$BccAddr.'>' . "\r\n";
$headers .= 'From: '.$FromName.' <'.$FromAddr.'>' . "\r\n";
$headers .= 'Content-type: text/plain' . "\r\n";
// mail function is php's interface to sendmail
mail($ToName.' <'.$ToAddr.'>', $Subject, $Content, $headers);
//print $ToName.'<br>';
//print $ToAddr.'<br>';
//print $BccName.'<br>';
//print $BccAddr.'<br>';
//print $FromName.'<br>';
//print $FromAddr.'<br>';
//print $Subject.'<br>';
//print $Content.'<br>';
}
?> 4. Logon as an administrator and use "Email Server Configuration" to enable emailing and configure your addresses etc.
5. Test mail.php in isolation by using the following form. Just pop it in your forum directory but for security reasons remove it once you are happy mail.php works fine:
<HTML>
<BODY>
<form action=mail.php method=post>
<input type=text name=ToName> ToName<br>
<input type=text name=ToAddr> ToAddr<br>
<input type=text name=FromName> FromName<br>
<input type=text name=FromAddr> FromAddr<br>
<input type=text name=Subject> Subject<br>
<textarea name=Content></textarea><br>
<input type=submit name=Send value="Send">
</form>
</BODY>
</HTML> A useful tip when debugging is to right click in the browser and pull up the source of the page sending the mail (do it immediately after sending to ensure that the page is not replaced by an "email sent successfully" page or something similar). Then scan through the generated source for the forms/iframes and check that each has the correct email parameters etc. If you still have problems then make the form controls visible, use a manual submit, and increase the iframe dimensions so you can see any php error messages.
All email features I have tested appear to work just fine, pop emails, registration emails, pending registrations, forgotten passwords, subscribing to a forum or topic, etc. Note that you may get a click from your browser for each email sent (as it loads the php page in each iframe). On a dial up connection this could take a second or so per email, so you might not want to enable subscriptions unless the forum or topic is locked and only written to by moderators who will understand that they must wait for any clicks to complete. If this becomes a major problem for you then a more elegant solution would be to use form spoofing to call mail.php directly from ASP rather than use a self submitting form and iframe. Alternatively you could use inc_mail.asp to write each email to a database table, create a php script to send an email for each row and wipe the table clean, then load this script in a single hidden iframe at the end of any page that includes inc_mail.asp. If I find some time I will post such a solution here .
|
Edited by - Brett Alcock on 09 September 2005 08:39:46 |
|
Yamaboy
Starting Member
46 Posts |
Posted - 01 September 2005 : 13:01:48
|
I will give this a shot. Thanks so much to everyone who has helped with this topic. |
 |
|
ruirib
Snitz Forums Admin
    
Portugal
26364 Posts |
|
Brett Alcock
New Member

65 Posts |
Posted - 02 September 2005 : 08:00:38
|
Should have but guess there were problems?
quote: Originally sent by Yamaboy on 31 August 2005 16:28 GMT
I am totally lost with trying to get the sendmail feature working with unix/linux and wondered if you had any interest in helping me out.
|
Edited by - Brett Alcock on 02 September 2005 08:15:22 |
 |
|
ruirib
Snitz Forums Admin
    
Portugal
26364 Posts |
|
Brett Alcock
New Member

65 Posts |
Posted - 02 September 2005 : 12:17:47
|
Well I hope one of them gets implemented else we have both wasted our time.
|
 |
|
Yamaboy
Starting Member
46 Posts |
Posted - 06 September 2005 : 17:29:46
|
quote: Originally posted by ruirib
I emailed a set of changed files, according to your previous post, on the 30th. Had no reply.
Sorry, I did get those and still had no success. I am going to try this mod (hopefully this afternoon) and if it doesn't work then I am obviously screwing something up. Make no mistake, I appreciate your help. I'll let you know how it goes. |
 |
|
Yamaboy
Starting Member
46 Posts |
Posted - 06 September 2005 : 18:34:57
|
Made the updates and these seemed to work. It looks to me like there is a slight php problem (on my site at least). When I test the mail.php feature, an e-mail is sent to the webmaster but there is no subject, sender, etc. Also, no e-mails are sent to anyone other than the webmaster when adding new members/changing profiles/etc.
This is the error I get when testing.
Warning: preg_replace(): Unknown modifier 't' in /home/xxxxx/public_html/forum/mail.php on line 8
From what I can gather this is a parsing or syntax problem? It's so close to working. Any idea on what will fix this? |
 |
|
Brett Alcock
New Member

65 Posts |
Posted - 08 September 2005 : 07:33:28
|
To be sure there are no obvious mistakes in the above, I've just copied the php and html form back from this page, then uploaded and tested them without any problems. So it might be down to your php platform. Line 8 is dealing with regular expresions, so for now just remove the clean() function completely, and try again (Note you will need to actually remove the preg_replace line completely rather than comment it out otherwise the ?> will make php think the script is being terminated prematurely). For example:<?php
if(isset($_REQUEST['ToName'])) { // if we have posted data
$BccName = 'Webmaster';
$BccAddr = 'webmaster@yoursite.com';
$headers = 'Bcc: '.$BccName.' <'.$BccAddr.'>' . "\r\n";
$headers .= 'From: '.$FromName.' <'.$FromAddr.'>' . "\r\n";
$headers .= 'Content-type: text/plain' . "\r\n";
// mail function is php's interface to sendmail
mail($ToName.' <'.$ToAddr.'>', $Subject, $Content, $headers);
}
?> Failing that place the following script in your root directory (call it info.php or something), then run it to find out what version your php is and what modules it supports etc. You can then check at http://www.php.net to see what functions your version and build of php should support.
<html>
<body>
<?php
phpinfo();
?>
</body>
</html> Check also that you are uploading your php script in ascii mode (not binary), and take a quick view of the files content on the server using notepad or something, occasionally one can find the CRLF conversion between Windows and Unix has left the odd line improperly terminated (you will see a non-printable character instead of a line feed). The easiest way I have found to resolve this is to just retype those lines in the source and re-upload it. |
Edited by - Brett Alcock on 09 September 2005 08:35:50 |
 |
|
Brett Alcock
New Member

65 Posts |
Posted - 08 September 2005 : 08:37:53
|
Another thing is to check your PHP register_globals directive, the script above assumes it is on, and so references the post variables directly. However there are many ways to reference post data in PHP depending upon your particular servers configuration. If register_globals is off (it is by default since PHP 4.2.0) then try the following script which uses the $_POST superglobals array (available since PHP 4.1.0) now widely accepted as the preferred method. If this does not work then try using the old predefined $HTTP_POST_VARS array (available since PHP 3.0 but now depreciated). This could certainly explain the loss of post data you seemed to be experiencing. Note: original post updated to reflect this change<?php
function clean($dirty) {
$clean="";
while($clean!=$dirty) { // removes any html tags
$clean=$dirty;
$dirty=preg_replace("/<.*?>/", "", $clean);
}
return $clean;
}
if(isset($_POST)) { // if we have posted data
// clean 'all' posted data incase form spoofed etc
$ToName = clean($_POST['ToName']);
$ToAddr = clean($_POST['ToAddr']);
$FromName = clean($_POST['FromName']);
$FromAddr = clean($_POST['FromAddr']);
$Subject = clean($_POST['Subject']);
$Content = clean($_POST['Content']);
$BccName = 'Webmaster';
$BccAddr = 'webmaster@yoursite.com';
$headers = 'Bcc: '.$BccName.' <'.$BccAddr.'>' . "\r\n";
$headers .= 'From: '.$FromName.' <'.$FromAddr.'>' . "\r\n";
$headers .= 'Content-type: text/plain' . "\r\n";
// mail function is php's interface to sendmail
mail($ToName.' <'.$ToAddr.'>', $Subject, $Content, $headers);
//print $ToName.'<br>';
//print $ToAddr.'<br>';
//print $BccName.'<br>';
//print $BccAddr.'<br>';
//print $FromName.'<br>';
//print $FromAddr.'<br>';
//print $Subject.'<br>';
//print $Content.'<br>';
}
?> |
Edited by - Brett Alcock on 09 September 2005 08:24:41 |
 |
|
Yamaboy
Starting Member
46 Posts |
Posted - 08 September 2005 : 12:16:04
|
Holy crap, that second script seems to have fixed it. I have tested and everything seems to work. What can I say. Wow. And thanks to ruirib too for all his help. Muchos gracias. |
 |
|
ruirib
Snitz Forums Admin
    
Portugal
26364 Posts |
|
Brett Alcock
New Member

65 Posts |
Posted - 09 September 2005 : 06:14:16
|
quote: Originally sent by Yamaboy on 08 September 2005 17:27 GMT
That second fix got it. It must have been a platform issue. You Sir, are a gentleman and a scholar. Seriously, thanks so much for helping me out with this. Hopefully some other people can use your script too.
Very pleased it worked for you. I've updated the original post above to reflect this and thus support a wider php base.
|
Edited by - Brett Alcock on 09 September 2005 07:17:36 |
 |
|
Kekke
Starting Member
3 Posts |
Posted - 15 October 2005 : 15:21:15
|
I will just tell all folks that this also works with b-one. |
 |
|
|
Topic  |
|