Hyperlink in php variable for email

Well, I thought I was through asking questions, but each day I look at our site, I find new issues that I missed. So, here is my next issue. I have a form that a user can fill out (like the contact us form). But instead of sending the actual message, I just want to send a simple message in the mail saying that the user has an awaiting message.

This is what I have now:

$body = "You have a new message awaiting. Please login to your account at <a href='http://mytherapysession.com/mtsdemo'>MTS Demo @ MyTherapySession</a>";

but instead of the email showing:

You have a new message awaiting. Please login to your account at MTS Demo @ MyTherapySession

it displays:

You have a new message awaiting. Please login to your account at <a href='http://mytherapysession.com/mtsdemo'>MTS Demo @ MyTherapySession</a>

 

I would greatly appreciate if someone could point out what I am doing wrong. Thanks in advance.

email message.png · 229.4K · 157 views
caredesign.net
Quote · 24 Sep 2013

Not enough information to go on.

How are you sending the email? Need to see more of the code other than the body variable.

What functions are used to send the email?

https://www.deanbassett.com
Quote · 24 Sep 2013

 $aForm = array(
            'form_attrs' => array(
                'name'     => 'form_Contact',
                'method'   => 'post',
            ),

            'params' => array (
              
                      'db' => array(
                    'table' => 'sys_messages', // table name
                    'key' => 'ID', // key field name
                    'uri' => '', // uri field name
                    'uri_title' => '', // title field to generate uri from
                    'submit_name' => 'submit_contact_form', // some filed name with non empty value to determine if the for was submitted,
                                                       // in most cases it is submit button name
                ),
                'csrf' => array(
                      'disable' => true, //if it wasn't set or has some other value then CSRF checking is enabled for current form, take a look at sys_security_form_token_enable to disable CSRF checking completely.
                )
              ),
            'inputs' => array(
                'header1' => array(
                    'type' => 'hidden',
                ),
        'Name' => array(
            'type' => 'text',
            'name' => 'Subject',
                      'db' => array (
                        'pass' => 'Xss', 
                    ),
            'caption' => _t("Name"),
            'checker' => array (
                'func' => 'length',
                'params' => array(3, 256),
                'error' => _t('_sys_adm_form_err_required_field'),
            ),
        ),
        'Email' => array(
            'type' => 'text',
            'name' => 'Email',
                      'db' => array (
                        'pass' => 'Xss', 
                    ),
            'caption' => _t("Email"),
            'checker' => array (
                'func' => 'length',
                'params' => array(3, 256),
                'error' => _t('_sys_adm_form_err_required_field'),
            ),
        ),
        'Phone' => array(
            'type' => 'text',
            'name' => 'Phone',
                      'db' => array (
                        'pass' => 'Xss', 
                    ),
            'caption' => _t("Phone Number"),
        ),
        'Message' => array(
            'type' => 'textarea',
            'name' => 'Text',
                      'db' => array (
                        'pass' => 'Xss', 
                    ),
            'caption' => _t("Message"),
        ),
        'Captcha' => array(
            'type' => 'slider',
            'name' => 'replace_captcha',
            'caption' => _t("Slide to Right"),
            'checker' => array (
                'func' => 'length',
                'params' => array(3, 3),
                'error' => _t('Please slide to the right to verify you are human'),
            ),
        ),
                'header1_end' => array(
                    'type' => 'block_end'
                ),
             'submit_send' => array(
            'type' => 'submit',
                    'colspan' => true,
            'name' => 'submit_contact_form',
            'value' => _t("Send"),
        ),
             ),
        );

        $oForm = new BxTemplFormView ($aForm);
        $oForm->initChecker();

        if ($oForm->isSubmittedAndValid ()) {
$profileID = getID( $_GET['ID'] );
            // add additional vars to database, in this case creation date field is added
            $aValsAdd = array (
            'sender' => $_COOKIE['memberID'],
            'recipient' => $profileID,
            );
if ($oForm->insert ($aValsAdd)) {

 $to = "myemail@gmail.com";
 $subject = "New Contact at MTSDemo from " . $_POST['Subject'];
 $body = "You have a new message awaiting. Please login to your account at <a href='http://mytherapysession.com/mtsdemo'>MTS Demo @ MyTherapySession</a>";
 $from = $_POST['Email'];
 $headers = "From: " . $from;
              
                if (mail($to, $subject, $body, $headers)) {
$sStatusText = 'Message Successfully Sent. We will contact you soon, but will not leave a phone message.';
  } else {
$sStatusText = 'Message Not Sent';
  }

            }
        }
                if($sStatusText)
            $sStatusText = MsgBox(_t($sStatusText), 3);

        return array($sStatusText . $oForm->getCode(), array(), array(), false);

caredesign.net
Quote · 24 Sep 2013

Try changing this line.

$body = "You have a new message awaiting. Please login to your account at <a href='http://mytherapysession.com/mtsdemo'>MTS Demo @ MyTherapySession</a>";

That is not valid html. The quotes are wrong.

Try this instead.

$body = 'You have a new message awaiting. Please login to your account at <a href="http://mytherapysession.com/mtsdemo">MTS Demo @ MyTherapySession</a>';

I reversed the quotes.

Look into using dolphins mail function.  sendMail in inc/utils.inc.php

So instead of using php mail, use dolphin sendMail like so.

sendMail( $to, $subject, $body);

https://www.deanbassett.com
Quote · 24 Sep 2013

If you insist on using the mail built into php, then you will need to add.

Content-type: text/html; charset=UTF-8\r\n to the headers.

Add this line
$headers = "Content-type: text/html; charset=UTF-8\r\n" . $headers;

After this line
$headers = "From: " . $from;


https://www.deanbassett.com
Quote · 24 Sep 2013

made changes you suggested regarding the "/' and I get the same result

email message1.png · 225.5K · 156 views
caredesign.net
Quote · 24 Sep 2013

 

made changes you suggested regarding the "/' and I get the same result

 We posted at the same time. Read my last post. Missing headers.

Dolphins built in function would do that for you.


https://www.deanbassett.com
Quote · 24 Sep 2013

OK, using the sendMail, and your reversal of the quotes, I get the proper message as I want it to display, thanks again for your time and assistance. The only difference I have now is that the From in my email says:

MTS Demo @ MyTherapySession

instead of the persons Email address, but I can live with that. It actually may be better since the mail is technically coming from the site and not the user themselves.

Now I have to edit my other post about adding blocks to the contact us page - lol

 

 

 

 

email message2.png · 207.7K · 153 views
caredesign.net
Quote · 24 Sep 2013

Yea, you can't pass a from line to dolphins function. It uses a combination of site title and sites notify settings.

https://www.deanbassett.com
Quote · 24 Sep 2013

One last thing I am having an issue with - if you look, I have hard coded my email address, but I want to use the $site['email'] variable. When using this variable the message is not sent via mail.

caredesign.net
Quote · 24 Sep 2013

There is no site['email'] in the global parameters.

The only one available via the site global is the bug report address.

If you want the sites email address you use the getParam function to get it from the sys_options table of the database.

$email = getParam('site_email'); or for the sites notify address use $email = getParam('site_email_notify'); and for the bug report address use $email = $GLOBALS['site']['bugReportMail'];



https://www.deanbassett.com
Quote · 24 Sep 2013

i was playing around with things trying to figure out what was going on. I basically used the form from the original contact.php page and made edits of fields that we wanted, and in the contact.php page, it uses the $site['email'] variable. I made this change and it works now:

$to = getParam('site_email');;
 $subject = "New Contact at MTSDemo from " . $_POST['Subject'];
 $body = 'You have a new message awaiting. Please login to your account at <a href="http://mytherapysession.com/mtsdemo">MTS Demo @ MyTherapySession</a>';
              
                if (sendMail($to, $subject, $body)) {

 

but this is what the contact.php page has:

        $sLetterBody = $sLetterBody . "\r\n" . '============' . "\r\n" . _t('_from') . ' ' . $sSenderName . "\r\n" . 'with email ' .  $sSenderEmail;

        if (sendMail($site['email'], $sLetterSubject, $sLetterBody)) {

so I was under the impression that the variable would work since the index.php page calls the db.inc.php (form is on the homepage) page like the contact.php page does. But Hey, it is working now, and that is all that matters. Thanks again.

caredesign.net
Quote · 24 Sep 2013

I suppose it's possible it's added to the global scope later in dolphin. If it's used in the contact us, then it must be.

But there is a trick to using the globals.

You must either have this at the top of the function it's used in.

global $site;

Before you can use it.

$email = $site['email'];


Or it can be accessed this way which is the method i use most often. This does not require it be declared as a global at the top of the function.

$email = $GLOBALS['site']['email'];


My guess is when you were trying to use it, you did not have the global $site declaration at the top of the function thus the value was empty.




https://www.deanbassett.com
Quote · 24 Sep 2013
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.