Customer Portal

Get Involved. Join the Conversation.

Topic

    Janusz Jasinski
    How to send an email?Answered
    Topic posted June 7, 2017 by Janusz JasinskiSilver Crown: 22,500+ Points 
    414 Views, 8 Comments
    Title:
    How to send an email?
    Content:

    Hi,

    I put the code below in a controller (code from http://documentation.custhelp.com/euf/assets/devdocs/august2016/Connect_PHP/Default.htm)

    However I'm getting loads of errors. Any help?

    <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

    <h4>A PHP Error was encountered</h4>

    <p>Severity: Notice</p>
    <p>Message:  Use of undefined constant MOD_BUILD_VER - assumed 'MOD_BUILD_VER'</p>
    <p>Filename: 3.3.3/optimized_includes.php</p>
    <p>Line Number: 6966</p>

    </div>
    <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

    <h4>A PHP Error was encountered</h4>

    <p>Severity: Notice</p>
    <p>Message:  Undefined offset: 1</p>
    <p>Filename: 3.3.3/optimized_includes.php</p>
    <p>Line Number: 9718</p>

    </div>
    <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

    <h4><br />
    <b>Notice</b>:  Undefined property: Custom\Controllers\AjaxMail::$rnow in <b>/cgi-bin/MYDOMAIN.cfg/scripts/cp/customer/development/errors/error_php.php</b> on line <b>3</b><br />
    A PHP Error was encountered</h4>

    <p>Severity: Warning</p>
    <p>Message:  Cannot modify header information - headers already sent by (output started at /cgi-bin/MYDOMAIN.cfg/scripts/cp/core/framework/3.3.3/CodeIgniter/system/CoreCodeIgniter.php:1169)</p>
    <p>Filename: system/CoreCodeIgniter.php</p>
    <p>Line Number: 1260</p>

    </div>
    <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

    <h4>A PHP Error was encountered</h4>

    <p>Severity: Warning</p>
    <p>Message:  Cannot modify header information - headers already sent by (output started at /cgi-bin/MYDOMAIN.cfg/scripts/cp/core/framework/3.3.3/CodeIgniter/system/CoreCodeIgniter.php:1169)</p>
    <p>Filename: system/CoreCodeIgniter.php</p>
    <p>Line Number: 1292</p>

    </div>
    <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

    <h4>A PHP Error was encountered</h4>

    <p>Severity: Warning</p>
    <p>Message:  Cannot modify header information - headers already sent by (output started at /cgi-bin/MYDOMAIN.cfg/scripts/cp/core/framework/3.3.3/CodeIgniter/system/CoreCodeIgniter.php:1169)</p>
    <p>Filename: 3.3.3/optimized_includes.php</p>
    <p>Line Number: 4524</p>

    </div>
    <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

    <h4>A PHP Error was encountered</h4>

    <p>Severity: Warning</p>
    <p>Message:  Cannot modify header information - headers already sent by (output started at /cgi-bin/MYDOMAIN.cfg/scripts/cp/core/framework/3.3.3/CodeIgniter/system/CoreCodeIgniter.php:1169)</p>
    <p>Filename: 3.3.3/optimized_includes.php</p>
    <p>Line Number: 4593</p>

    </div>
    <br><hr><br><br><br><br>Sent.

    Code Snippet:

    Best Comment

    Bastiaan van der Kooij

    You should not use InitConnectApi in the Customer Portal as Connect is already loaded for you. Your Controller should look something like;

    <?php
    namespace Custom\Controllers;
    use RightNow\Connect\v1_3 as RNCPHP;
    
    class AjaxCustom extends \RightNow\Controllers\Base
    {
        function __construct()
        {
            parent::__construct();
        }
        
        function sendMail()
        {
            // your code here
            // Call this function like: /ci/ajaxCustom/sendMail
        }
    }
    

    Comment

     

    • Bastiaan van der Kooij

      You should not use InitConnectApi in the Customer Portal as Connect is already loaded for you. Your Controller should look something like;

      <?php
      namespace Custom\Controllers;
      use RightNow\Connect\v1_3 as RNCPHP;
      
      class AjaxCustom extends \RightNow\Controllers\Base
      {
          function __construct()
          {
              parent::__construct();
          }
          
          function sendMail()
          {
              // your code here
              // Call this function like: /ci/ajaxCustom/sendMail
          }
      }
      
    • Janusz Jasinski

      What I had worked - the errors mad eme think it wasn't and emails were delayed

    • Bastiaan van der Kooij

      well if you can improve it a bit by not having your controller spit out its guts, while trying to send a mail is always nice :)

    • Pramod Vasudeva Murthy

      <p>Severity: Warning</p>
      <p>Message:  Cannot modify header information - headers already sent by (output started at /cgi-bin/MYDOMAIN.cfg/scripts/cp/core/framework/3.3.3/CodeIgniter/system/CoreCodeIgniter.php:1169)</p>
      <p>Filename: 3.3.3/optimized_includes.php</p>
      <p>Line Number: 4593</p>

      </div>
      <br><hr><br><br><br><br>Sent.

      After you resolve all your issues, if you come across this error still - remove all the echo statements and print_r statements because the controller will hold the browser(browser memory) to display this message.

      ~VIP

    • Barrilito van Dijk

      Hi,

      In general you say you copied some full sample code from the oracle documentation and it does not work.

      Try to let us know in more detail what you are doing. You state you put the code in a controller. I guess that means a custom controller like Bastiaan gave you a small sample piece of code. But how did you test it, and why put in such a large piece of code from an example?  How literal should I take your code? Did you realy test this with the email addresses in it as you have them here, realy with an admin1 account set up?  Sample code is meant to get you in the right direction. When you use it in a controller, you should first make a tiny controller with practically no code in it then perhaps one echo line in it to test. If you would have done that as Bastiaan described, you could test if that sendMail function could be called via the url without errors. Does it work, then proceed to add the code for sending an email, and then still I would suggest to start small.

      For us it is not clear what you have done or tested, and if your controller does not work in general or if your code within it does not work.

      Makes sense?

      Regards

    • JJ

      As said - it was resolved. Just spitting out warnings which confused me

    • Vijayalakshmi Arunachalam

      Hi I tried below code, it says there was some error in your request

       

      <?php
      require_once(get_cfg_var("doc_root") . "/ConnectPHP/Connect_init.php");
      //ini_set('display_errors', 'On');
      error_reporting(E_ALL);
      //use RightNow\Connect\v1_3 as RNCPHP;
       
      //initConnectAPI("admin1", "Admin1");
       
      $email_1 = "vijiarunachalam@yahoo.com";
      $email_2 = "example1@tet.com";
      $email_3 = "john.anderson@example.com";
      $text_body = "Sample text body:\nThe text part of the message.";
      $html_body = "<h3>HTML body:</h3>\nThe <b>HTML</b> part of the message.";
       
      echo "<br><hr><br>";
      echo "<br>";
      try {
          echo "<br>";
          //Create a sample contact who has not opted in
         /* $contact_optin_false = new RightNow\Connect\v1_3\Contact();
          $contact_optin_false->Name->First = "First_1";
          $contact_optin_false->Name->Last = "Last_1";
          $contact_optin_false->Emails = new RightNow\Connect\v1_3\EmailArray();
          $email = new RightNow\Connect\v1_3\Email();
          $email->Address = $email_3;
          $email->AddressType->ID = 0;
          $contact_optin_false->Emails[] = $email;
          $contact_optin_false->save();*/
       
      //create mail message object
          $mm = new RightNow\Connect\v1_3\MailMessage();
       
      //set TO,CC,BCC fields as necessary
          $mm->To->EmailAddresses = array($email_1);
       //   $mm->To->EmailUsers = array($contact_optin_false);
       
          $mm->CC->EmailAddresses = array($email_2);
       
      //set subject
          $mm->Subject = "Message from Oracle Service Cloud";
       
      //set body of the email
          $mm->Body->Text = $text_body;
          $mm->Body->Html = $html_body;
       
      //set marketing options
          $mm->Options->IncludeOECustomHeaders = false;
       
      //send email
          $mm->send();
          echo "<br>Sent.";
      }
      catch ( \Exception $err ){
          echo "<br><b>Exception</b>: line ".__LINE__.": ".$err->getMessage()."</br>";
      }
      ?>

      <p>
      A request has been raised for adhoc support from a Field Engineer. Please choose to either Accept or Reject this request.
      </p>

       

       

    • Pramod Vasudeva Murthy

      This is an old thread, please open a new one.

      For Public Mail API to work, you must have:

      • An Outgoing mailbox
      • Instance should be greater then Aug 2014 version
      • Email address must be a valid one

      Make sure you have all of the above pre-requisite.

      ~VIP