Construct AT command string

I am trying to build a system with an Arduino Mega and a SIM900 development board. The idea is to send a text message to the system which then responds with a text message to the sender. I can detect and decode the incoming message but when i construct the AT command for the respond I fail. If I hardcode the command it works fine but the constructed code wont work even if it looks the same.
I have tried and tested different solution for over a week now but am probably barking up the wrong tree.

void sendSMS()
{
  int i, k;
  char cmd[26];
  char cmd1[] = {'"', 'A', 'T', '+', 'C', 'M', 'G', 'S', '=', 92, '"'}; //Start of SMS string
  char cmd3[] = {92, '"', '"'};                                         //End of SMS string
  
  for (i = 0; i < sizeof(cmd1); i++)
  {
    cmd[i] = cmd1[i];
  }
  k = i;

  for (i = 1; i < sizeof(phone)-1; i++)                                 //Phone,exclude '\0'
  {
    cmd[k] = phone[i];
    k++;
  }

  for (i = 0; i < sizeof(cmd3); i++)
  {
    cmd[k] = cmd3[i];
    k++;
  }
  cmd[k]='\0';
  Serial.print("cmd: ");        //Debug
  Serial.println(cmd);          //Debug
  Serial3.print("AT+CMGF=1\r");
  delay(100);
  //Serial3.println("AT+CMGS=\"+46705957262\"");    // THIS WORKS
  Serial3.println(String(cmd));                     // THIS DOES NOT WORK, 
  Serial.println(String(cmd));                      //Serial monitor shows "AT+CMGS=\"+46705957262\""

   delay(50);
  Serial3.print("Sugga i Suntak!");
  delay(100);
  Serial3.println((char)26);
}

It is probably something quite basic I miss but I just can't put my finger on it.

Are you zero terminating your arrays of chars in order to turn them into string ?

Why are you converting your string into a String ?

Hi
I do only zero terminate the last array. The last string to String is just the last try, using cmd as it is gives the same result

Please post a complete program illustrating the problem
What is the phone variable, for instance ?

This is where the problem is, I have cleaned it a bit but it works/errors the same way.

#include <string.h>
#include <hardwareSerial.h>

String readString;

int recieving_counter = 0;
const byte numChars = 200;
char SMSin[numChars];
char tempChars[numChars];        // temporary array for use when parsing
// variables to hold the parsed data
char message[numChars] = {0};
char messagetemp[numChars] = {0};
char datum[20] = {0};
char datumtemp[20] = {0};
char tid[20] = {0};
char phone[14] = {0};
boolean newData = false;


void setup() {

  Serial.begin(19200);
  delay(100);
  Serial3.begin(115200);
  delay(200);
  //Serial3.print("AT");
  //Serial3.print("ATEO");  //Echo off
  delay(100);
  Serial3.print("AT+CMGF=1\r");
  delay(100);
  Serial3.print("AT+CNMI=1,2,0,0,0\r");
  delay(100);


}


void loop() {
  receiveSMS(); //SMS
  delay(1000);

  if (newData == true)
  {
    strcpy(tempChars, SMSin);
    parseData();
    showParsedData();
    memset(&SMSin[0], 0, sizeof(SMSin));
    checkmessage();
    newData = false;
  }
}

void sendSMS()
{
  int i, k;
  char cmd[26];
  char cmd1[] = {'"', 'A', 'T', '+', 'C', 'M', 'G', 'S', '=', 92, '"'}; //Start of SMS string
  char cmd3[] = {92, '"', '"'};                                         //End of SMS string

  for (i = 0; i < sizeof(cmd1); i++)
  {
    cmd[i] = cmd1[i];
  }
  k = i;

  for (i = 1; i < sizeof(phone) - 1; i++)                               //Phone,exclude '\0'
  {
    cmd[k] = phone[i];
    k++;
  }

  for (i = 0; i < sizeof(cmd3); i++)
  {
    cmd[k] = cmd3[i];
    k++;
  }
  cmd[k] = '\0';
  Serial.print("cmd: ");        //Debug
  Serial.println(cmd);          //Debug
  Serial3.print("AT+CMGF=1\r");
  delay(100);
 // Serial3.println("AT+CMGS=\"+46705957262\"");    // THIS WORKS
  Serial3.println(cmd);                     // THIS DOES NOT WORK,
  Serial.println(cmd);                      //Serial monitor shows "AT+CMGS=\"+46705957262\""

  delay(50);
  Serial3.print("Sugga i Suntak!");
  delay(100);
  Serial3.println((char)26);
}

void parseData() {      // split the data from SMS into its parts
  int ndx;
  int offset;
  char phoneTemp[20] = {0};
  int k = 0;
  memset(&messagetemp[0], 0, sizeof(messagetemp));
  memset(&message[0], 0, sizeof(message));

  char * strtokIndx; // this is used by strtok() as an index

  strtokIndx = strtok(tempChars, ":");  //Clean beginning


  strtokIndx = strtok(NULL, ",");     // get the first part - the string
  strcpy(phoneTemp, strtokIndx);

  for (int i = 0; i < sizeof(phoneTemp); i++)
  {
    if (phoneTemp[i] != '"')
    {
      phone[k] = phoneTemp[i];
      k++;
    }
  }

  strtokIndx = strtok(NULL, ",");     // jump empty part

  strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
  strcpy(datumtemp, strtokIndx);

  ndx = 0;
  offset = 1;
  while (ndx <= sizeof(datumtemp))
  {
    if (ndx >= offset)
    {
      datum[ndx - offset] = datumtemp[ndx];
    }
    ndx++;
  }

  strtokIndx = strtok(NULL, "+"); // this continues where the previous call left off
  strcpy(tid, strtokIndx);

  strtokIndx = strtok(NULL, "\0");
  strcpy(messagetemp, strtokIndx);

  ndx = 0;
  offset = 5;
  while (ndx <= sizeof(messagetemp) )
  {
    if (ndx >= offset)
    {
      message[ndx - offset] = messagetemp[ndx];
    }
    ndx++;
  }
}

void showParsedData() //Only debug
{
  Serial.print("Message: ");
  Serial.println(message);
  Serial.print("Datum: ");
  Serial.println(datum);
  Serial.print("Time: ");
  Serial.println(tid);
  Serial.print("Phone: ");
  Serial.println(phone);
}

void receiveSMS()
{
  static byte ndx = 0;
  char rc;
  if (Serial3.available() > 0)
  {
    while (Serial3.available() > 0 && newData == false) {
      rc = Serial3.read();
      SMSin[ndx] = rc;
      ndx++;
      delay(20);
      if (ndx >= numChars) {
        ndx = numChars - 1;
      }
    }
    SMSin[ndx] = '\0'; // terminate the string
    ndx = 0;
    newData = true;
  }
}

void checkmessage()
{
  char * pch;
  pch = strstr (message, "GetStatus");
  if (pch != NULL)
  {
    Serial.println("Hoppsan");
    sendSMS();
  }

}