Announcement

Collapse
No announcement yet.

use values from php in robust html email

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • use values from php in robust html email

    Hello all,

    I was wondering if anyone knew how to output values from php into an html email. Currently I have a table with the html email code which works properly. However, the emails are a little vague because I don't know how to display field values in the html email. I'm currently attempting to send a robust html email containing a generated password for password recovery. That works great but I can only get the email to display the text with the temp password. I want to liven up the plain email but not sure where to put the html. I tried events and php methods to store the html code but can't figure out how to pass the variable $decrypt from the code below.

    PHP Code:
    /**
     * Check for an existing record
     */

    // SQL statement parameters
    $check_table 'sdh_sec_users';    // Table name
    $check_where "login = '{login}' AND email = '{email}'"// Where clause

    // Check for record
    $check_sql 'SELECT *'
       
    ' FROM '  $check_table
       
    ' WHERE ' $check_where;
    sc_select(dataset$check_sql);

    if (
    false == {dataset})
    {
        
    // Error while accessing database
    }
    elseif ({
    dataset}->EOF)
    {
        
    // No record found
        
    sc_error_message('The user or email you have entered was not found in the system');
    }
    else
    {
        
    $decrypt = {pswd};
        {
    pswd} = md5({pswd});


        
    // Record found
    // SQL statement parameters
    $update_table  'sdh_sec_users';      // Table name
    $update_where  "login = '{login}'"// Where clause
    $update_fields = array(   // Field list, add as many as needed
         
    "pswd = '{pswd}'",
        
    "reset = '{reset}'",
    );
        
    // Update record
    $update_sql 'UPDATE ' $update_table
        
    ' SET '   implode(', '$update_fields)
        . 
    ' WHERE ' $update_where;
    sc_exec_sql($update_sql);
        
        
    sc_commit_trans();


            
    $mail_smtp_server 'mail.123comply.com';
            
    $mail_smtp_user 'temp@123comply.com';
            
    $mail_smtp_pass '1mpac7c0mp1y';
            
    $mail_from 'temp@123comply.com';
           



    $check_sql2 "SELECT login, pswd"
       
    " FROM sdh_sec_users"
       
    " WHERE login = '" . {login} . "'";
    sc_lookup(rs$check_sql2);

    if (isset({
    rs[0][0]}))     // Row found
    {
        
    $mail_subject "Your password has been reset";
        
        
    $temppasswd = [$_POST($decrypt)];
        
    $mail_message email();
        
    //$mail_message ="Your temporary password is: ". $decrypt;
        //$mail_message ="Your temporary password is". {rs[0][1]};

    }

    $check_sql3 "SELECT email"
       
    " FROM sdh_sec_users"
       
    " WHERE email = '{email}'";
    sc_lookup(rs$check_sql3);

    if (isset({
    rs[0][0]}))     // Row found
    {
        
    $mail_to = {rs[0][0]};
    }
    $mail_format      'H';                     

    // Send email
    {
    sc_mail_send($mail_smtp_server,
                 
    $mail_smtp_user,
                 
    $mail_smtp_pass,
                 
    $mail_from,
                 
    $mail_to,
                 
    $mail_subject,
                 
    $mail_message,
                 
    $mail_format);

    }
    }
        
    sc_commit_trans();
    sc_redir(password_confirmation.php'','_parent'); 
    I hope I've made my issue clear enough. Any help would greatly appreciated.
    Last edited by ancr2001; 05-29-2015, 12:11 PM.

  • #2
    $mail_message='Your temporary password is:'.$temppasswd;

    I have no idea why you do: $mail_message = email();

    Be aware that you send HTML format mail so you need to make it HTML...

    Comment


    • #3
      First you need to set the mail format to html. Then you can just fill the body with html text. I use a tinymce editor to create a mail template and substitute the variables by field data before sending it by email. All standard sc rules apply conceirning {} fields, but you can also use your own tags and do a php replacestr.
      Albert Drent
      aducom software netherlands
      scriptcase partner, reseller, support and (turn-key) development
      www.scriptcase.eu / www.scriptcase.nl

      Comment


      • #4
        Thanks guys,

        I figured it out now. @rr $mail_message = email(); was just a test. I meant to exclude that. It was working with $mail_message = $decrypt;. Also, the format of the message is already "H". Since SC has some quirks with code that works outside of SC I had to change all " to ' because the html " was fighting with the php ". Also, since php tags are backwards, you close php to add html and reopen so it looks like it's backwards, echoing a value from php to html is usually <?php echo "Hello world!";?>. That doesn't work in this case. What does work is just plainly putting the value $decrypt smack dab in the html.

        Like so:
        PHP Code:
        $mail_message "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
        <html xmlns='http://www.w3.org/1999/xhtml'>

        <table style='background-color: #ffffff; ; width: 100%;' border='0' align='center'>
        <tbody>
        <tr>
        <td>
        <table style='background-color: #ffffff; width: 943px; height: 475px; border-color: #cecece; border-width: 1px; border-style: solid;' border='1' cellspacing='0' align='center'>
        <tbody>
        <tr>
        <td style='height: 150px; text-align: left; background-color: #ffffff;'>
        <table style='width: 936px; height: 117px;' border='0' align='center'>
        <tbody>
        <tr>
        <td>
        <img src='http://www.test.com/logo.png' alt='logo' width='343' height='76' />
        </td>
        <td align='right' valign='top'>
        <p style='text-align: center;'>
        <span style='font-size: 28px; color: #0087ca;'>
        <span style='font-weight: bold;'>
        <span class='color_5'>Title 1</span>
        </span>
        </span>
        </p>
        <p style='text-align: center;'>
        <span style='color: #37cc00;'>
        <span style='font-size: 17px;'>
        <span style='letter-spacing: 0.64em;'>
        <span style='font-weight: bold;'>Title 2</span>
        </span>
        </span>
        </span>
        </p>
        <p style='text-align: center;'>
        <span style='color: #0087ca;'>
        <span style='font-size: 17px;'>
        <span class='color_5'>Title 3</span>
        </span>
        </span>
        </p>
        </td>
        </tr>
        </tbody>
        </table>
        </td>
        </tr>
        <tr>
        <td style='border-color: #cecece; border-style: solid; border-width: 1px;' scope='row' align='left' valign='top'>
        <p>
        <span style='font-size: x-large; color: #3366ff;'>Notification!</span>
        </p>
        <p>
        <span style='font-size: large; color: #000000;'>Your Password has been reset. Please login and change your temporary password.</span>
        $decrypt
        </p>
        </td>
        </tr>
        <tr>
        <td style='height: 50px; background-image: url('http://www.test.com/logo.png');'>
        <p style='text-align: center;'>
        <span style='color: #ffffff;'>
        <strong>
        <span style='font-size: medium;'>Footer 1</span>
        </strong>
        </span>
        </p>
        <p style='text-align: center;'>
        <span style='color: #ffffff;'>
        <strong>
        <span style='font-size: medium;'>
        <span style='font-size: small;'>
        <strong>Footer 2</strong>
        </span>
        </span>
        </strong>
        </span>
        </p>
        </td>
        </tr>
        </tbody>
        </table>
        </td>
        </tr>
        </tbody>
        </table>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <body>
        </body>
        </html>"

        Thanks again for your help. It's been a long week.

        Comment

        Working...
        X