如何压制这个对象(stdClass)#5(2){[“errorNumber”] => int(0)[“scriptResult”] => object(stdClass)#6(0){}}

时间:2015-04-17 11:24:40

标签: php email gmail phpmailer stdclass

我正在使用PHPMailer根据用户输入从我的网站发送电子邮件。 我唱这个代码。虽然我能够发送电子邮件并完成所需的工作,但是,我正在网页上看到这个。

object(stdClass)#5(2){[“errorNumber”] => int(0)[“scriptResult”] => object(stdClass)#6(0){}}

我正在使用Gmail发送电子邮件。我是PHP的新手。

public function sendorderemail() {
    //SMTP needs accurate times, and the PHP time zone MUST be set
    //This should be done in your php.ini, but this is how to do it if you don't have access to that
    date_default_timezone_set('Etc/UTC');

    require '../mail/PHPMailerAutoload.php';

    // Stop error reporting
    error_reporting(0);

    //Create a new PHPMailer instance
    $mail = new PHPMailer;

    //Tell PHPMailer to use SMTP
    $mail->isSMTP();

    //Enable SMTP debugging
    // 0 = off (for production use)
    // 1 = client messages
    // 2 = client and server messages
    $mail->SMTPDebug = 0;

    //Ask for HTML-friendly debug output
    $mail->Debugoutput = 'html';

    $mail->IsHTML(true);

    //Set the hostname of the mail server
    $mail->Host = 'smtp.gmail.com';

    //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
    $mail->Port = 587;

    //Set the encryption system to use - ssl (deprecated) or tls
    $mail->SMTPSecure = 'tls';

    //Whether to use SMTP authentication
    $mail->SMTPAuth = true;

    //Username to use for SMTP authentication - use full email address for gmail
    $mail->Username = "xxx@gmail@gmail.com";

    //Password to use for SMTP authentication
    $mail->Password = "xxxxxxxx";

    //Set who the message is to be sent from
    $mail->setFrom('xxx@gmail.com', 'MyCompany A/S');

    //Set an alternative reply-to address
    $mail->addReplyTo('xxx@gmail.com', 'MyCompany A/S');

    //Set who the message is to be sent to
    $mail->addAddress('xxxx@MyCompany.dk', 'xxx xxxx');
    //$mail->addAddress('xxxxx@MyCompany.dk', 'xxxx xxxx');
    if($this->kundeemail != ""){
            $mail->addAddress($this->kundeemail,$this->kunderekvirent);
        }

    //Set the subject line
    $mail->Subject = "robot@MyCompany.dk - don't reply.";   

    //Attach the image files
    $mail->addAttachment($this->fil1);
    $mail->addAttachment($this->fil2);


    //Read an HTML message body from an external file, convert referenced images to embedded,
    //convert HTML into a basic plain-text alternative body
    $mail->Body    = '
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Untitled Document</title>
        <style type="text/css">
        body,td,th {
            font-family: Arial;
            font-size: 11px;
        }
        </style>
        </head>

        <body>
          <p>Tak for din bestilling.<br />
          <br />
          Du har bestil '.$this->antal.' stk. med f&oslash;lgende oplysninger:<br />'.$this->kommentar.'</p>


        <h3>Preview</h3>
         <p>Forside:</p>
         <p><img class="previewimage" width="250px" style="border:1px solid #cecece; " src="http://web2MyCompany.dk/uploads/'.$this->fil1.'" /></p>
         <p>Bagside:</p>
         <p><img class="previewimage" width="250px" style="border:1px solid #cecece; "  src="http://web2MyCompany.dk/uploads/'.$this->fil2.'" /></p>
        <h3>Fakturaadresse</h3>
        <table width="400" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td>Firmanavn</th>
            <td>'.$this->kundefirmanavn.'</th>
          </tr>
          <tr>
            <td>CVR Nr.</td>
            <td>'.$this->kundecvr.'</td>
          </tr>
          <tr>
            <td>Telefon Nr.</td>
            <td>'.$this->kundetelefon.'</td>
          </tr>
          <tr>
            <td>Rekvirent</td>
            <td>'.$this->kunderekvirent.'</td>
          </tr>
          <tr>
            <td>Adresse</td>
            <td>'.$this->kundeadresse.'</td>
          </tr>
          <tr>
            <td>Postnr. &amp; By</td>
            <td>'.$this->kundepostnr.' '.$this->kundeby.'</td>
          </tr>
          <tr>
            <td>E-mail</td>
            <td>'.$this->kundeemail.'</td>
          </tr>
        </table>
        <h3>Leveringsadresse</h3>
        <table width="400" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td>Firmanavn</th>
            <td>'.$this->leveringfirmanavn.'</th>
          </tr>
          <tr>
            <td>CVR Nr.</td>
            <td>'.$this->leveringcvr.'</td>
          </tr>
          <tr>
            <td>Telefon Nr.</td>
            <td>'.$this->leveringtelefon.'</td>
          </tr>
          <tr>
            <td>Rekvirent</td>
            <td>'.$this->leveringrekvirent.'</td>
          </tr>
          <tr>
            <td>Adresse</td>
            <td>'.$this->leveringadresse.'</td>
          </tr>
          <tr>
            <td>Postnr. &amp; By</td>
            <td>'.$this->leveringpostnr.' '.$this->leveringby.'</td>
          </tr>
          <tr>
            <td>E-mail</td>
            <td>'.$this->leveringemail.'</td>
          </tr>
        </table>

        <p>Med venlig hilsen</p>
        <p>MyCompany A/S</p>
        </body>
        </html>
        ';

    //Replace the plain text body with one created manually
    $mail->AltBody = 'MyCompany A/S';



    //send the message, check for errors
    if (!$mail->send()) {
        echo "Error in Sending Email";
    } else {
        echo "Email Sent Successfully";

    }   
}

2 个答案:

答案 0 :(得分:1)

从我可以看到,上面发布的代码不会在您的脚本中创建输出。

描述的输出: object(stdClass)#5 (2) { ["errorNumber"]=> int(0) ["scriptResult"]=> object(stdClass)#6 (0) { } }

很可能是代码中某处的var_dump(或print_r)在json_decode或mysqli_fetch_object(或某些返回stdClass的类似函数)上的结果。

我建议您搜索您的脚本和其他“要求”#39; &#34; var_dump&#34;的文件并在找到后立即删除罪犯。

答案 1 :(得分:1)

看起来你的代码中已经使用了var_dump但我在你粘贴的代码中的任何地方都看不到它。也许代码中的其他地方。