0
while($row = mysql_fetch_object($all)) {
$name = $row->name;
$email = $row->email;
$id = $row->id;

$finished_text = '';
$news_content = '';
$buffer = '';

[...]

foreach($text_in_array as $word) {
    if($word == '[NAME]'){
        $buffer = $name;
    }else if($word == '[NAME].'){
        $buffer = $name.'.';
    }else if($word == '[NAME],'){
        $buffer = $name.',';
    }else if($word == '[NAME]!'){
        $buffer = $name.'!';
    }else if($word == '[NAME]"'){
        $buffer = $name.'"';
    }else if($word == '"[NAME]'){
        $buffer = '"'.$name;
    }else if($word == '"[NAME]"'){
        $buffer = '"'.$name.'"';
    }else if($word == '[NAME]."'){
        $buffer = $name.'."';
    }else if($word == '[NAME],"'){
        $buffer = $name.',"';
    }else if($word == '[NAME]!"'){
        $buffer = $name.'!"';
    }else if($word == '*[NAME]*'){
        $buffer = '*'.$name.'*';
    }else if($word == '**[NAME]**'){
        $buffer = '**'.$name.'**';
    }else if($word == '[EMAIL]'){
        $buffer = $email;
    }else if($word == '[EMAIL].'){
        $buffer = $email.'.';
    }else if($word == '[EMAIL],'){
        $buffer = $email.',';
    }else if($word == '[EMAIL]!'){
        $buffer = $email.'!';
    }else if($word == '[EMAIL]"'){
        $buffer = $email.'"';
    }else if($word == '"[EMAIL]'){
        $buffer = '"'.$email;
    }else if($word == '"[EMAIL]"'){
        $buffer = '"'.$email.'"';
    }else if($word == '[EMAIL]."'){
        $buffer = $email.'."';
    }else if($word == '[EMAIL],"'){
        $buffer = $email.',"';
    }else if($word == '[EMAIL]!"'){
        $buffer = $email.'!"';
    }else if($word == '*[EMAIL]*'){
        $buffer = '*'.$email.'*';
    }else if($word == '**[EMAIL]**'){
        $buffer = '**'.$email.'**';
    }else{
        $buffer = $word;
    }

    $news_content .= ' '.$buffer;
}
$finished_text .= Markdown($news_content);

[...]

mail(
    '[email protected]', //just test later it will be set to $email
    $betreff,
    $message,
    $header
);
}

I don't know why, but sometimes it works perfectly and sometimes it doesn't. Also interesting: Before I created a HTML email with this script, it only worked after I had changed the email address as the last change…

I hope someone can help me. Thanks.

6
  • Where do you get $text_in_array from ? Commented Sep 25, 2011 at 16:54
  • 2
    sometimes it works perfectly and sometimes it doesn't is not a useful error description at all... But anyway, this is crying out for a fundamental rewrite. Maybe the problem goes away all by itself once that has happened :) Commented Sep 25, 2011 at 16:54
  • German code? eww. Please use english for your identifiers etc. Besides that, the code is just horrible. Consider using string replacement... Commented Sep 25, 2011 at 16:55
  • @Pekka: Sorry. I can't describe it better, because I just don't understand it (for me it feels like random). Commented Sep 25, 2011 at 16:56
  • 1
    I don't think it's that terrible to use non-english identifiers if it's a hobby project. @NE well, you could show some input data and describe what happens when it doesn't work. But a rewrite would really be in order, maybe somebody who reads this can work out a suggestion Commented Sep 25, 2011 at 16:57

1 Answer 1

2
  1. You should be using a switch statement instead of that long string of ifs.
  2. What's wrong with $buffer = str_replace(Array("[NAME]","[EMAIL]"),Array($name,$email),$wort);?
  3. After cleaning that up, if you still get problems, please be more specific on what problems you are having.
Sign up to request clarification or add additional context in comments.

1 Comment

Oh… thanks! I didn't think about 'str_replace();'! I'll try it and get back to you. Thanks so much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.