I am facing a strange Error prob lem regarding the php Strings

can any one help me in understanding what happening in my codes? whether its a error in programming or is it due to php engine is malfuctioning? following are the code of a class which I am making to send emails very easly.. What I am trying to achieve :- I have defined functions for performing every task needend to send a mail from a simple text to a advance mail with multipart email with plain text, html formated and with attachment.

/*----------------------------------------------------------------------------------
   this function will take care of setting the mail depending users input what            he enters the message will be set up
 ----------------------------------------------------------------------------------*/
    public function set_mail_message($value)
{
$temp_message="";


// ----- detecting whether message submitted has html elements..]

if(strlen($value) != strlen(strip_tags($value)))
    {
    //...... message contains HTMLelements, so content type shud be 
    //....HTML type but for the compatiblity with older email clients
    //....we will set it to the both first html then plain text type..

    $temp_message.="This is a multipart message in MIME format";
    $temp_message.= "--".$this->boundary."\n";

    $temp_message.= "Content-type:text/html; charset=\"iso-8859-1\"\n";
    $temp_message.= "Content-Transfer-Encoding:7bit \n\n";

    $temp_message.= $value."\n";
    $temp_message.= "-- $this -> boundary \n";


//----------these codes from here-------------------------------

    $temp_message.= "Content-type:text/plain; charset=\"iso-8859-1\"\n";
    $temp_message.= "Content-Transfer-Encoding:7bit \n\n";
    $temp_message.= strip_tags($value)."\n";

 //--------------- upto HERE ARE OK................

//************ attach the attachment  prepared by function**********************/
        if($this->attachment_status == TRUE)
        {
        $temp_message.= "--".$this -> boundary."\n";

        $temp_message.= "Content-type: " . $Attachment_MIME_Type. "; \n name=\"$attachment_name\"\n";
        $temp_message.= "Content-Transfer_Encoding: base64\n\n";
        $temp_message.= $attachment_data."\n\n\";
        }       

    //----finishing the message configuration..........

    }
    else
    {
    // - ----content type is only PLAIN/TEXT---with or without attachmet-----
 //----------------BUT SAME CODES HERE FROM HERE :------------
    $temp_message.= '--'.$this->boundary.'\n';
    $temp_message.= 'Content-type:text/plain; charset=\"iso-8859-1\"\n'; 
    $temp_message.= 'Content-Transfer-Encoding:7bit \n\n';
    $temp_message.= $value.'\n';

//------------------UPTO HERE ARE SAME AS PREVIOUS BUT GIVING ERROR----------


//-------put attachment if set up by calling the set_mail_attachment function-------/
        if($this->attachment_status == TRUE)
        {
        $temp_message.= '--'.$this -> boundary.'\n';

        $temp_message.= 'Content-type: ' . $Attachment_MIME_Type. '; \n name=\'$attachment_name\'\n';
        $temp_message.= 'Content-Transfer_Encoding: base64\n\n';
        $temp_message.= $attachment_data.'\n\n';
        } 
        //----attachment has been put now close the boundary---

    $temp_message.= '--'.$this ->boundary.'--\n';
    }
$this ->message = $temp_message;

}



/*this function will take care of attchment and if this function is called and a 
atachment a selected only then the attachment part in set_mail_message() will be
defined*/   


   public function set_mail_attachment($value)
{

$attachment_data;

if(!empty($value) && file_exists($value))
    {
    $this -> attachment_status = TRUE;
//--here file type and file Name must be found somehow
//-- so that we can define them when seinding mail -------

    $Attachment_MIME_Type = 'image/jpeg';
    $attachment_name = 'attachment.jpeg';




    //------file must be read in binary format-------
    $file_resource = fopen($value,'rb')or die ('Error! There is an error in attachment');
    $attachment_data = fread($file_resource,filesize($value));
    fclose($file_resource);
    }

}

PROBLEM IS : as commented in code at two points the code are same but in second part same code generates parse error,to solve it i need to change dauble quote with single quotes,but doing this when i am calling the these both function and if i pass the argument in as Double quoted string then same parse error i get and if I use single quotes instead of double then I got another error: UNexpected $end..

I traversed my code many time tried to find soltions on net too. but NOT getting success in debugging this.. please if you can test the code please test it yourself too,so that problem can be traced.

Please help me.. my thanks in a

Answers


did you notice how in the question, the color formatting of your code block changes to red after this line?: $temp_message.= $attachment_data."\n\n\";

thats because \" is an escaped character, and its not actually closing your string.

it should be: $temp_message.= $attachment_data."\n\n";


Need Your Help


About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.