Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 关于php字符串,我面临一个奇怪的错误问题_String_Email_Php - Fatal编程技术网

String 关于php字符串,我面临一个奇怪的错误问题

String 关于php字符串,我面临一个奇怪的错误问题,string,email,php,String,Email,Php,有谁能帮助我理解代码中发生了什么?这是编程错误还是由于php引擎故障造成的? 下面是我制作的一个类的代码,可以很容易地发送电子邮件。。 我试图实现的目标:-我已经定义了执行每项任务所需的功能,即使用包含纯文本、html格式和附件的多部分电子邮件将邮件从简单文本发送到高级邮件 问题是:正如代码中两点的注释所示,代码是相同的,但在第二部分中,相同的代码会生成解析错误,为了解决这个问题,我需要用单引号更改dauble引号,但是,当我调用thisetweath函数时,如果我将参数作为双引号字符串传入,则

有谁能帮助我理解代码中发生了什么?这是编程错误还是由于php引擎故障造成的? 下面是我制作的一个类的代码,可以很容易地发送电子邮件。。 我试图实现的目标:-我已经定义了执行每项任务所需的功能,即使用包含纯文本、html格式和附件的多部分电子邮件将邮件从简单文本发送到高级邮件

问题是:正如代码中两点的注释所示,代码是相同的,但在第二部分中,相同的代码会生成解析错误,为了解决这个问题,我需要用单引号更改dauble引号,但是,当我调用thisetweath函数时,如果我将参数作为双引号字符串传入,则会出现相同的解析错误,如果我使用单引号而不是双引号,则会出现另一个错误:意外的$end

我多次遍历我的代码,试图在网上找到解决方案。但在调试过程中没有取得成功。。 如果你能测试代码,请你自己测试,这样问题就可以被追踪

请帮帮我。。
我在

中的感谢您是否注意到在问题中,代码块的颜色格式在这一行之后如何变为红色?:$temp\u message.=$attachment\u data。\n\n\

这是因为\是一个转义字符,它实际上并没有关闭字符串


它应该是:$temp\u message.=$attachment\u data。\n\n

我想你的问题是这一行:

$temp_message.=$attachment_data.\n\n\


字符串文字末尾的尾随反斜杠正在转义结束双引号,这将导致代码中出现解析错误

您是否知道现有的类phpmailer、swiftmailer,它们避免了繁琐的手工构造多部分消息?是的,mario,我非常了解这些类。。但是,在理解和学习编程时,你会同意我的观点吗?一个特定的问题有数百万种解决方案,但我认为作为一个学习者,尝试独自完成你想要的任务不是很好。。这有助于理解概念。感觉非常好。谢谢亲爱的!我想试试这个解决方案。谢谢你,亲爱的@Kristian@Thankyou亲爱的克里斯蒂安,它解决了我面临的问题。但现在我面临着另一个问题:发送邮件,现在发送代码中声明的邮件正文,而不是邮件的内容文本或html,我接收的邮件包含内容类型声明、内容传输编码以及我代码中定义邮件消息的所有内容。。。。。。。。。如果你能帮我做什么,我请求你。。。。
/*----------------------------------------------------------------------------------
   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);
    }

}