0

I have a script which read html files from directory and you can check which file use to php mail body. But the main problem, how to read checked file and assign it to php mail body?

This is my code:

/* Languages preliminaries */
        $defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));
        $languages = Language::getLanguages();
        $iso = Language::getIsoById($defaultLanguage);

        $dir = dirname(__FILE__) . "/mails/". $iso . "/" ;
        $files = scandir( $dir ) ;
        $cnt = count($files) ;

 $html = '      <a name="htmllist"></a>
            <form method="post" action="'.$_SERVER['REQUEST_URI'].'" >
  $html .= '<div>
                  <table>
                    <th>HTML FILES</th><th>Edit</th>
                    <th>Choose</th>'
                    ;
    $tokenModules = $_REQUEST['token'];

    for( $i = 0; $i < $cnt; $i ++ )
    {
        if( preg_match('/.html$/', $files[$i]) )
        {
            $link = '<a href="index.php?tab=AdminModules&token=' . $tokenModules . '&configure=' . urlencode($this->name) . '&file='.$files[$i].'#emaileditor">' ;
            $link .= '<img src="' . __PS_BASE_URI__ . 'img/admin/edit.gif" /></a>' ;

            $html .= '<tr>
                    <td>'. $files[$i] . '</td>
                    <td align="left">'.$link.'</td>
                    <td><input type="checkbox" name="which[]" value="'.$files[$i].'"> Use '. $files[$i] . ' template</td>
                  </tr>' ;
        }
    }
    $html .= '</table>' ;
    $html .= '</div>' ;

So here I can see all files and near file name I can check. I think that i need check array[] , yes?

But how to get information which is checked? And assign that file to php body?

$to = 'mymail@mail.com';
$subject = "hello";
$body = "";
$headers = 'From: info@mydomain.com' . "\r\n" ;
$headers .= 'Reply-To: info@mydomain.com' . "\r\n";
$headers .= 'BCC: ' . implode(', ', $recipients) . "\r\n";
mail($to, $subject, $body, $headers);

This is my mail to funkcion.

Satish Sharma
  • 9,547
  • 6
  • 29
  • 51
elPresta
  • 633
  • 10
  • 17

2 Answers2

0

There's a mess with quotes, it should look like this: (note the closing quote)

 $html = '      <a name="htmllist"></a>
            <form method="post" action="'.$_SERVER['REQUEST_URI'].'" >';

You have to start using some IDE, I think...

k102
  • 7,861
  • 7
  • 49
  • 69
  • You are my hero, but in other stack question I can see only $message = `' content – elPresta Aug 05 '14 at 07:38
  • 1
    Do not ever use `@`! You don't see if there's an error (and I guess it's there). And never trust user input! `$filename = $_REQUEST['which'];` is really a bad idea – k102 Aug 05 '14 at 09:57
  • Thank u, I remove @ and use POST. Thank you. – elPresta Aug 06 '14 at 09:02
0

This:

<input type="checkbox"/>

should be:

<input type="radio"/>

if you only want to select 1 template file for your email.

Then the following code:

<input type="radio" name="which[]" value="'.$files[$i].'">

should be:

<input type="radio" name="which[]" value="'.$dir.$files[$i].'">

This way you have the whole template path in that input. Now, you can get the template by using $_POST['which'].

Later edit:

To send HTML emails, take a look at this https://stackoverflow.com/a/11239033/1057527

Community
  • 1
  • 1
machineaddict
  • 3,216
  • 8
  • 37
  • 61
  • It works perfect. Almost.. I get all HTML content in my email, but I can`t see it as TEXT, I see all html code

    message from

    asdasd
    and etc... `$filename = $_POST['which']; $cotents = file_get_contents( $filename ) ; $cotents = Tools::htmlentitiesUTF8($cotents); $cotents = htmlspecialchars_decode($cotents); $cotents = str_replace("\r\n", PHP_EOL, $cotents); if (_PS_MAGIC_QUOTES_GPC_) $cotents = stripslashes($cotents); $body = $cotents; ` but it not works.
    – elPresta Aug 06 '14 at 09:00
  • Well, I see you didn't checked the link I gave you. There is says how to send HTML emails. – machineaddict Aug 06 '14 at 09:50
  • I checked, but yesterday. But I can say: u are my hero! It works! Thank u , thank u , thanku ! – elPresta Aug 06 '14 at 10:02