0

I'm new to Expression Engine, I'm hoping someone can help me out with an issue? I'm sure I'm missing something obvious. What I'm trying to do is send an email.

My template code looks like this:

{embed="main/header1"}
<meta name="Description" content="whatever">
<meta name="Keywords" content="stuff">
{embed="main/header2"}
{embed="main/navbar"}

{exp:channel:entries channel="subscription" limit="1"}
<div id="content2">
<div id="Image">
    <img src="{page_image}" alt="alt text" /></div>
<div id="Content">
    <?php
    echo $_GET['email_address'];
    ?>

$email_msg = "email address: $email_val";
$email_to = "email@address.com"

ee()->load->library('email');
ee()->load->helper('text');

ee()->email->wordwrap = true;
ee()->email->mailtype = 'text';
ee()->email->from("Expression Engine");
ee()->email->to($email_to);

ee()->email->subject(Test);
ee()->email->message(entities_to_ascii($email_msg));
ee()->email->Send();
</div>
</div>
{/exp:channel:entries}
{embed="main/footer"}

All of the EE library code is outputting to the screen as text, rather than being executed. What am I missing? Thanks for your help. PHP is enabled. - James.

0

You have just closed PHP end tag in wrong place. You just need to put a PHP end tag after your PHP Mail code. So, try my suggested code as below. I hope it will work for you.

{embed="main/header1"}
<meta name="Description" content="whatever">
<meta name="Keywords" content="stuff">
{embed="main/header2"}
{embed="main/navbar"}

{exp:channel:entries channel="subscription" limit="1"}
<div id="content2">
    <div id="Image">
        <img src="{page_image}" alt="alt text" />
    </div>
    <div id="Content">
    <?php
        echo $_GET['email_address'];

        $email_msg = "email address: $email_val";
        $email_to = "email@address.com"

        ee()->load->library('email');
        ee()->load->helper('text');

        ee()->email->wordwrap = true;
        ee()->email->mailtype = 'text';
        ee()->email->from("Expression Engine");
        ee()->email->to($email_to);

        ee()->email->subject(Test);
        ee()->email->message(entities_to_ascii($email_msg));
        ee()->email->Send();
    ?>
    </div>
</div>
{/exp:channel:entries}
{embed="main/footer"}
1
  • Thanks! That solved my issues. I'd also left out a semi-colon. Jul 7 '18 at 9:59
0

You need to put your php code inside php tags.

{embed="main/header1"} 
{embed="main/header2"} 
{embed="main/navbar"}
{exp:channel:entries channel="subscription" limit="1"}
<?php
   $email_msg = "email address: $email_val"; 
   $email_to = "email@address.com" ee()->load->library('email');
   ee()->load->helper('text'); 
   ee()->email->wordwrap = true; 
   ee()->email->mailtype = 'text';
   ee()->email->from("Expression Engine"); 
   ee()->email->to($email_to); 
   ee()->email->subject(Test); 
   ee()->email->message(entities_to_ascii($email_msg)); 
   ee()->email->Send();
?>
{/exp:channel:entries} {embed="main/footer"}

More in the EE documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.