Unable to send MMS via GSM/GPRS SIM900 shield

hello guys,

I am trying to send an image from sdcard (.jpg ) via GSM/GPRS SIM900 shield on arduino mega 2560. I have no compilation and uploading error. But when I have opened the Serial Monitor and give AT Commands (in my case 1,2,3,4 and s to start mms), after performing several functions well it is displaying me that it can not receive the recipient phone number. (I think there is some problem with the "AT+CMMSRECP="+97152xxxxxxx"\r" operation).

Here is my code:

/*
Project: Send MMS from SD Card Lesson
Programmer: Shahrulnizam Mat Rejab
Board: Arduino Mega
Last Modified: 14 December 2014
Website: http://shahrulnizam.com
*/

#include <SD.h>


#define  CS    53

File dataFile;
int i;
unsigned char data=0;

void setup()
{
  
  pinMode(CS,OUTPUT);
  Serial.begin(9600);
  Serial2.begin(19200);
  
  delay(10);
 
  delay(10);
  if (!SD.begin(CS)) Serial.println("initialization failed!");
  else Serial.println("initialization done.");  
}

void loop()
{
  if(Serial2.available())
  {
    while(Serial2.available())
    {
      data=Serial2.read();
      Serial.write(data);
    }
    data=0;
  }
  
  if(Serial.available())
  {
    data=Serial.read();
  }  
  
  if(data=='1')
  {
    Serial2.print("AT+CGMI\r"); //Manufacturer identification
  }  
  if(data=='2')
  {
    Serial2.print("AT+CGMM\r"); //Model identification
  }
  
  if(data=='3')
  {
    Serial2.print("AT+CGMR\r"); //Software version
  }
  
  if(data=='4')
  {
    Serial2.print("AT+CGSN\r"); //IMEI number
  }
  
  if(data=='5')
  {
    Serial2.print("ATD+97152xxxxxxx;\r"); //Calling
  }
  
  if(data=='6')
  {
    Serial2.print("ATH\r"); //Hang Up
  }
  
  if(data=='7')
  {
    Serial2.print("AT+CMGF=1\r"); //Set text mode
    delay(100);
    Serial2.print("AT+CMGS="); //Send message
    Serial2.write((byte)0x22); //"
    Serial2.print("+97152xxxxxxxx"); //Phone no
    Serial2.write((byte)0x22); //"
    Serial2.write((byte)0x0D); //Enter
    Serial2.print("Hai, I'm Arduino");//Text message
    Serial2.write((byte)0x0D); //Enter
    Serial2.print("Reply, if you receive this message");//Text message
    Serial2.write((byte)0x1A); //Ctrl+Z
  }
  
  if(data=='8')
  {
    Serial2.print("AT+CMGR=1\r"); //Read message
  }
  
  if(data=='9')
  {
    Serial2.print("AT+CMGD=1,0\r"); //Delete message
  }  
  
  if(data=='s') sendMMS();
  data=0;
}

void sendMMS()
{
  Serial2.print("AT+CMMSINIT\r");
  delay(100);
  if(Serial2.available())
  {
    while(Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+CMMSCURL=\"http://mms.du.ae:8002\"\r");
  delay(100);
  if(Serial2.available())
  {
    while(Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+CMMSCID=1\r");
  delay(100);
  if(Serial2.available())
  {
    while(Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+CMMSPROTO=\"10.19.18.4\",8080\r");
  delay(100);
  if(Serial2.available())
  {
    while(Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+CMMSSENDCFG=6,3,0,0,2,4\r");
  delay(100);
  if(Serial2.available())
  {
    while(Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+SAPBR=3,1,\"Contype\",\"GPRS\"\r");
  delay(100);
  if(Serial2.available())
  {
    while(Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+SAPBR=3,1,\"APN\",\"du\"\r");
  delay(100);
  if(Serial2.available())
  {
    while(Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+SAPBR=1,1\r");
  delay(4000);
  if(Serial2.available())
  {
    while(Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+SAPBR=2,1\r");
  delay(1000);
  if(Serial2.available())
  {
    while(Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+CMMSEDIT=1\r");
  delay(100);
  if(Serial2.available())
  {
    while(Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+CMMSDOWN=\"PIC\",19293,2000000,\"Capture.jpg\"\r");
  delay(1000);
  if(Serial2.available())
  {
    while(Serial2.available()) Serial.write(Serial2.read());
  }

  dataFile=SD.open("Capture.jpg");
  i=0;
  if(dataFile)
  {
    while(dataFile.available())
    {
      data=dataFile.read();
      if(data<0x10) Serial.print("0");
      Serial.print(data,HEX);
      i++;
      if((i%40)==0) Serial.println();
      Serial2.write(data);
    }
    dataFile.close();
  }  
  else
  {
    Serial.println("error opening Capture.jpg");
  }

  delay(1000);
  Serial2.print("AT+CMMSRECP=\"+97152xxxxxxx\"\r");
  delay(100);
  if(Serial2.available())
  {
    while(Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+CMMSVIEW\r");
  delay(2000);
  if(Serial2.available())
  {
    while(Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+CMMSSEND\r");
  delay(2000);
  if(Serial2.available())
  {
    while(Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+CMMSEDIT=0\r");
  delay(2000);
  if(Serial2.available())
  {
    while(Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+CMMSTERM\r");
  delay(2000);
  if(Serial2.available())
  {
    while(Serial2.available()) Serial.write(Serial2.read());
  }
}

Thanks in advance for help.

don't post your phone number if it's the real one...

you could simplify this code

  if(Serial2.available())
  {
    while(Serial2.available()) Serial.write(Serial2.read());
  }

into    while(Serial2.available()) Serial.write(Serial2.read()); (and you could make that a function)

Note that you are not guaranteed to read everything that is sent back this way if the answer is long as you'll likely empty the buffer faster than the data arrives; Usually AT commands are confirmed with an "OK\r\n" so you could have a small function waiting for that to arrive (or timeout - this way you'll know the command has likely failed)

Thanks for help,

J-M-L:
don't post your phone number if it's the real one...

you could simplify this code

  if(Serial2.available())

{
   while(Serial2.available()) Serial.write(Serial2.read());
 }



into


while(Serial2.available()) Serial.write(Serial2.read());



(and you could make that a function) 

Note that you are not guaranteed to read everything that is sent back this way if the answer is long as you'll likely empty the buffer faster than the data arrives; Usually AT commands are confirmed with an "OK\r\n" so you could have a small function waiting for that to arrive (or timeout - this way you'll know the command has likely failed)

I have done these changes but it doesn't help me send the image in MMS, it even add some additional errors.

Can you suggest me of other solutions?

Thanks in advance

Regards
Amew