Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mail script error with strtok

Status
Not open for further replies.

tty0

Programmer
Nov 13, 2002
108
GB
Hi all

I have got a problem, i have taken a script but theres one part I dont understand, It works for me when I write the mail line and variables myself but when i use this script it falls over. As I say i have written my own but i'd still like to understand why this fals on its arse.

The lines i have a problems with are the strtok ones. For some reason it uses rn as the token. But when I use my name "chris" and my email "chris@techsupport...." after those lines it strips them back to "ch".

But what has got me is that the name and string fields are stored correctly in $name and $email, but if I comment out the strtok lines the script doesnt work at all.

clueless :-s
*******************************************************
$mailto = $_POST['email'];
$subject = "RCB Assist site - download locations";
$formurl = "$errorurl = "$thankyouurl = "
$name = $_POST['name'];
$email = $_POST['email'];
$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit;
}
if (empty($name) || empty($email)) {
header( "Location: $errorurl" );
exit;
}
$name = strtok( $name, "rn" );
$email = strtok( $email, "rn" );

$messageproper =

"This message was sent from:\n" .
"$http_referrer\n" .
"--------------------------Message----------------------------------\n" .
"Name:$name\n" .
"Email:$email\n" .
"
Dear $name,

message body
" .
"\n-------------------------------------------------------------------\n";

mail($mailto, $subject, $messageproper, "From: $name <$email>rnReply-To: $name);

<$email>rnX-Mailer: Mailer v1.0" );
header( "Location: $thankyouurl" );
exit;
*******************************************************

'mi casa es su casa'
]-=tty0=-[
 
You tokenize the string on the string "rn".
If you are referring to the carriage return and newline chars you should precede them with the backslash "\r\n".
 
ive tried that but it doesn't process the script at all. Its like if there is no carriage return or new line characters then it doesnt store anything.

Yet if I comment out the strtok lines and let the email address pass through the script normally it still doesnt process.

Yet if i use strtok with say an r and type chris into the boxes it sends the email out with my name but when it comes to the message body and the header about the mailer it just says "ch"

'mi casa es su casa'
]-=tty0=-[
 
The strtok lines IMHO are superfluous or could be replaced with something else... Now we just need to find out where the rest fails.
Are there any error messages?

Now to the explanation of the 'ch':
strttok tokenizes a string, i.e. splits it up at a specific character/string in steps. You start tokenizing a string 'chris' with 'rn'. The token 'rn' works that any of the characters are used for delimiters.
In this case, 'r' is found and the result is the portion of the string up to 'r' --> ch

The author of the script probably expected either a carriage return or a newline at the end of the name and/or email address. They used strtok to cut off any excess information.

This explains the ch, but doesn't solve the mail problem. Put some footprinting code in there and check if the mail() function returns 'true'.
 
hanks for the explanation,

I have changed the headers in the email so it must have been something to do with that, but im still not sure why a malformed email address would have any effect on the headers when the mailto field and the recipient fields were correctly formatteed.

:)
cheers


'mi casa es su casa'
]-=tty0=-[
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top