moktoman
06-29-2007, 06:03 AM
Ok, I will try to put this as simply as possible:
I have a mailer script I got from a website somewhere (I don't recall where exactly) that is successfully sending emails to a specific email account, the content of which is given from an HTML feedback form on my server.
Here is the script:
<?php
$To = 'webtester800@mywebserver.com';
$SmtpServer = 'smtp.mywebserver.com';
$SmtpUserid = 'webtester800@mywebserver.com';
$SmtpPassword = '******';
$NextPage = 'fbgood.html';
$Debug = 0;
function ReceiveOnSocket($Socket,$Ok,$Debug) {
$Line = '';
do {
$Result = fgets($Socket,10000);
if ($Result == FALSE) return('Error reading from socket');
$Line = $Line . $Result;
if ($Debug > 0) echo '<<< ' . htmlentities(trim($Result)) . "\n";
} while ($Result[3] == '-');
if (intval($Line) != $Ok) return($Line);
return('');
}
function SendOnSocket($Socket,$Message,$Debug) {
if ($Debug > 0) echo '>>> ' . htmlentities(trim($Message)) . "\n";
if (fputs($Socket,$Message) == FALSE) return('Error sending: ' . $Message);
return('');
}
function SendEmail(
$SmtpServer,
$SmtpPort,
$Userid,
$Password,
$To,
$From,
$ReplyTo,
$Subject,
$Body,
$Debug) {
if ($SmtpServer == '') return('No SmtpServer specified');
if ($SmtpPort == '') return('No SmtpPort specified');
if ($To == '') return('No TO address specified');
if ($From == '') return('No FROM address specified');
if ($ReplyTo == '') return('No REPLYTO address specified');
if ($Subject == '') return('No SUBJECT specified');
if ($Body == '') return('No BODY specified');
$Socket = fsockopen($SmtpServer,$SmtpPort,&$errno,&$errstr);
if ($Socket == FALSE) return('Cannot connect to mailserver');
$Status = '';
if ($Status == '') $Status = ReceiveOnSocket($Socket,220,$Debug);
if ($Status == '') $Status = SendOnSocket($Socket,'HELO ' . $SmtpServer . "\r\n",$Debug);
if ($Status == '') $Status = ReceiveOnSocket($Socket,250,$Debug);
if (($Userid != '') && ($Password != '')) {
if ($Status == '') $Status = SendOnSocket($Socket,"AUTH LOGIN\r\n",$Debug);
if ($Status == '') $Status = ReceiveOnSocket($Socket,334,$Debug);
if ($Status == '') $Status = SendOnSocket($Socket,base64_encode($Userid) . "\r\n",$Debug);
if ($Status == '') $Status = ReceiveOnSocket($Socket,334,$Debug);
if ($Status == '') $Status = SendOnSocket($Socket,base64_encode($Password) . "\r\n",$Debug);
if ($Status == '') $Status = ReceiveOnSocket($Socket,235,$Debug);
}
if ($Status == '') $Status = SendOnSocket($Socket,'MAIL FROM:<' . $From . '>' . "\r\n",$Debug);
if ($Status == '') $Status = ReceiveOnSocket($Socket,250,$Debug);
$a = explode(',',$To);
for ($i = 0; $i < count($a); $i++) {
if (trim($a[$i]) == '') continue;
if ($Status == '') $Status = SendOnSocket($Socket,'RCPT TO:<' . trim($a[$i]) . '>' . "\r\n",$Debug);
if ($Status == '') $Status = ReceiveOnSocket($Socket,250,$Debug);
}
if ($Status == '') $Status = SendOnSocket($Socket,"DATA\r\n",$Debug);
if ($Status == '') $Status = ReceiveOnSocket($Socket,354,$Debug);
if ($Status == '') $Status = SendOnSocket($Socket,
'To: ' . $To . "\r\n" .
'From: ' . $From . "\r\n" .
'Reply-To: ' . $ReplyTo . "\r\n" .
'Subject: ' . $Subject . "\r\n" .
'Date: ' . date('D, d M Y H:i:s ') . "\r\n" .
"\r\n" .
trim($Body) .
"\r\n.\r\n",$Debug);
if ($Status == '') $Status = ReceiveOnSocket($Socket,250,$Debug);
if ($Status == '') $Status = SendOnSocket($Socket,"QUIT\r\n",$Debug);
if ($Status == '') $Status = ReceiveOnSocket($Socket,221,$Debug);
if ($Socket) fclose($Socket);
return ($Status);
}
if (isset($HTTP_GET_VARS)) {
while ($a = each($HTTP_GET_VARS)) {
if ($a[0] == 'From') continue;
if ($a[0] == 'Subject') continue;
if ($a[0] == 'Submit') continue;
$Body .= $a[0] . "\t= " . $a[1] . "\r\n";
}
}
if (isset($HTTP_POST_VARS)) {
while ($a = each($HTTP_POST_VARS)) {
if ($a[0] == 'From') continue;
if ($a[0] == 'Subject') continue;
if ($a[0] == 'Submit') continue;
$Body .= $a[0] . "\t= " . $a[1] . "\r\n";
}
}
$Subject = ereg_replace("[^-[:alnum:]_.!@=* ]","",$Subject);
$From = ereg_replace("[^-[:alnum:]_.!@=* ]","",$From);
if ($Debug != 0) echo '<pre>';
$Status = SendEmail($SmtpServer,25,$SmtpUserid,$SmtpPassword,
$To,$From,$From,$Subject,$Body,$Debug);
if ($Debug != 0) echo '</pre>';
if ($Status != '') {
if ($Debug == 0) echo '<html><body>' . "\n";
echo '<b>An error has occurred while sending the email.' . "\n";
echo 'The status message is:</b>' . "\n";
echo '<p>' . "\n";
echo htmlentities($Status,ENT_QUOTES) . "\n";
echo '</body></html>' . "\n";
exit;
}
if ($Debug == 0) header('location: ' . $NextPage);
?>
Now, my issue is that the emails that this script is sending has the content formatted something like this:
Great websiteName = John
Body = Great website
Submit_x = 22
Submit_y = 4
Optimistically, I would like the emails to not have the "Name =","Body =","Submit =" etc., plus the message or body content repeats twice. Once at beginning and once after "Body ="...
I am not very knowledgeable in PHP scripting, so I am not sure what part of the script is formatting the emails, and what needs to be changed to remedy the situation...?
Thanks in advance for any help you guys can give me!!
- Michael
I have a mailer script I got from a website somewhere (I don't recall where exactly) that is successfully sending emails to a specific email account, the content of which is given from an HTML feedback form on my server.
Here is the script:
<?php
$To = 'webtester800@mywebserver.com';
$SmtpServer = 'smtp.mywebserver.com';
$SmtpUserid = 'webtester800@mywebserver.com';
$SmtpPassword = '******';
$NextPage = 'fbgood.html';
$Debug = 0;
function ReceiveOnSocket($Socket,$Ok,$Debug) {
$Line = '';
do {
$Result = fgets($Socket,10000);
if ($Result == FALSE) return('Error reading from socket');
$Line = $Line . $Result;
if ($Debug > 0) echo '<<< ' . htmlentities(trim($Result)) . "\n";
} while ($Result[3] == '-');
if (intval($Line) != $Ok) return($Line);
return('');
}
function SendOnSocket($Socket,$Message,$Debug) {
if ($Debug > 0) echo '>>> ' . htmlentities(trim($Message)) . "\n";
if (fputs($Socket,$Message) == FALSE) return('Error sending: ' . $Message);
return('');
}
function SendEmail(
$SmtpServer,
$SmtpPort,
$Userid,
$Password,
$To,
$From,
$ReplyTo,
$Subject,
$Body,
$Debug) {
if ($SmtpServer == '') return('No SmtpServer specified');
if ($SmtpPort == '') return('No SmtpPort specified');
if ($To == '') return('No TO address specified');
if ($From == '') return('No FROM address specified');
if ($ReplyTo == '') return('No REPLYTO address specified');
if ($Subject == '') return('No SUBJECT specified');
if ($Body == '') return('No BODY specified');
$Socket = fsockopen($SmtpServer,$SmtpPort,&$errno,&$errstr);
if ($Socket == FALSE) return('Cannot connect to mailserver');
$Status = '';
if ($Status == '') $Status = ReceiveOnSocket($Socket,220,$Debug);
if ($Status == '') $Status = SendOnSocket($Socket,'HELO ' . $SmtpServer . "\r\n",$Debug);
if ($Status == '') $Status = ReceiveOnSocket($Socket,250,$Debug);
if (($Userid != '') && ($Password != '')) {
if ($Status == '') $Status = SendOnSocket($Socket,"AUTH LOGIN\r\n",$Debug);
if ($Status == '') $Status = ReceiveOnSocket($Socket,334,$Debug);
if ($Status == '') $Status = SendOnSocket($Socket,base64_encode($Userid) . "\r\n",$Debug);
if ($Status == '') $Status = ReceiveOnSocket($Socket,334,$Debug);
if ($Status == '') $Status = SendOnSocket($Socket,base64_encode($Password) . "\r\n",$Debug);
if ($Status == '') $Status = ReceiveOnSocket($Socket,235,$Debug);
}
if ($Status == '') $Status = SendOnSocket($Socket,'MAIL FROM:<' . $From . '>' . "\r\n",$Debug);
if ($Status == '') $Status = ReceiveOnSocket($Socket,250,$Debug);
$a = explode(',',$To);
for ($i = 0; $i < count($a); $i++) {
if (trim($a[$i]) == '') continue;
if ($Status == '') $Status = SendOnSocket($Socket,'RCPT TO:<' . trim($a[$i]) . '>' . "\r\n",$Debug);
if ($Status == '') $Status = ReceiveOnSocket($Socket,250,$Debug);
}
if ($Status == '') $Status = SendOnSocket($Socket,"DATA\r\n",$Debug);
if ($Status == '') $Status = ReceiveOnSocket($Socket,354,$Debug);
if ($Status == '') $Status = SendOnSocket($Socket,
'To: ' . $To . "\r\n" .
'From: ' . $From . "\r\n" .
'Reply-To: ' . $ReplyTo . "\r\n" .
'Subject: ' . $Subject . "\r\n" .
'Date: ' . date('D, d M Y H:i:s ') . "\r\n" .
"\r\n" .
trim($Body) .
"\r\n.\r\n",$Debug);
if ($Status == '') $Status = ReceiveOnSocket($Socket,250,$Debug);
if ($Status == '') $Status = SendOnSocket($Socket,"QUIT\r\n",$Debug);
if ($Status == '') $Status = ReceiveOnSocket($Socket,221,$Debug);
if ($Socket) fclose($Socket);
return ($Status);
}
if (isset($HTTP_GET_VARS)) {
while ($a = each($HTTP_GET_VARS)) {
if ($a[0] == 'From') continue;
if ($a[0] == 'Subject') continue;
if ($a[0] == 'Submit') continue;
$Body .= $a[0] . "\t= " . $a[1] . "\r\n";
}
}
if (isset($HTTP_POST_VARS)) {
while ($a = each($HTTP_POST_VARS)) {
if ($a[0] == 'From') continue;
if ($a[0] == 'Subject') continue;
if ($a[0] == 'Submit') continue;
$Body .= $a[0] . "\t= " . $a[1] . "\r\n";
}
}
$Subject = ereg_replace("[^-[:alnum:]_.!@=* ]","",$Subject);
$From = ereg_replace("[^-[:alnum:]_.!@=* ]","",$From);
if ($Debug != 0) echo '<pre>';
$Status = SendEmail($SmtpServer,25,$SmtpUserid,$SmtpPassword,
$To,$From,$From,$Subject,$Body,$Debug);
if ($Debug != 0) echo '</pre>';
if ($Status != '') {
if ($Debug == 0) echo '<html><body>' . "\n";
echo '<b>An error has occurred while sending the email.' . "\n";
echo 'The status message is:</b>' . "\n";
echo '<p>' . "\n";
echo htmlentities($Status,ENT_QUOTES) . "\n";
echo '</body></html>' . "\n";
exit;
}
if ($Debug == 0) header('location: ' . $NextPage);
?>
Now, my issue is that the emails that this script is sending has the content formatted something like this:
Great websiteName = John
Body = Great website
Submit_x = 22
Submit_y = 4
Optimistically, I would like the emails to not have the "Name =","Body =","Submit =" etc., plus the message or body content repeats twice. Once at beginning and once after "Body ="...
I am not very knowledgeable in PHP scripting, so I am not sure what part of the script is formatting the emails, and what needs to be changed to remedy the situation...?
Thanks in advance for any help you guys can give me!!
- Michael