經過STMP發郵件,這段代碼錯在哪

來源:互聯網
上載者:User
通過STMP發郵件,這段代碼錯在哪?
發不出郵件,也不返回錯誤提示。各位高手看看代碼錯在哪?

PHP code
 "smtp.gmail.com",    "port" => "465",    "username" => "", //使用者名稱    "password" => "", //密碼    "from" => "", //寄件者e-mail    "to" => "", //收件者e-mail    "subject" => "測試一下標題",    "body" => "測試一下內容"     );$CRLF = "\r\n";$test = "";$header = array( 'Return-path' => '<' . $smtp['from'] . '>',    'Date' => date( 'r' ),    'From' => '<' . $smtp['from'] . '>',    'MIME-Version' => '1.0',    'Subject' => inlineCode( $smtp['subject'] ),    'To' => $smtp['to'],    'Content-Type' => 'text/html; charset=UTF-8; format=flowed',    'Content-Transfer-Encoding' => 'base64'     );$data = buildHeader( $header ) . $CRLF . chunk_split( base64_encode( $smtp['body'] ) );$content = "EHLO " . $smtp["url"] . $CRLF; // 先得hello一下$content .= "AUTH LOGIN" . $CRLF . base64_encode( $smtp["username"] ) . $CRLF . base64_encode( $smtp["password"] ) . $CRLF; // 驗證登陸$content .= "MAIL FROM:" . $smtp["from"] . $CRLF; // 發件地址$content .= "RCPT TO:" . $smtp["to"] . $CRLF; // 收件地址$content .= "DATA" . $CRLF . $data . $CRLF . "." . $CRLF; // 發送內容$content .= "QUIT" . $CRLF; // 退出$curl = curl_init();curl_setopt( $curl, CURLOPT_URL, $smtp['url'] );curl_setopt( $curl, CURLOPT_PORT, $smtp['port'] );curl_setopt( $curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; .NET CLR 3.0.4506.2152)' );curl_setopt( $curl, CURLOPT_TIMEOUT, 10 );curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true ); // curl接收返回資料curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, false );curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, false );curl_setopt( $curl, CURLOPT_CUSTOMREQUEST, $content );$test = curl_exec( $curl );var_dump( $test );curl_close( $curl );function inlineCode( $str ) {    $str = trim( $str );    return $str ? '=?UTF-8?B?' . base64_encode( $str ) . '?= ' : '';} function buildHeader( $headers ) {    $ret = '';    foreach( $headers as $k => $v ) {        $ret .= $k . ': ' . $v . "\n";    }     return $ret;} ?>


------解決方案--------------------
不知道是不是1樓所說的問題

只能提供一個我用的發郵件的php,樓主可以試試
PHP code
                                                                debug = true; //是否開啟調試,只在測試程式時使用,正式使用時請將此行注釋                                $to = "收件者的郵件地址"; //收件者                                //準備使用的郵箱                                 $subject = "諮詢";                                $body=" 諮詢人:{$firstname}.{$familyname}
諮詢人名字拼音:{$firstnamepy}.{$familynamepy}
諮詢人性別:{$sex}
諮詢種類:{$zixun1}
諮詢內容:{$zixun}
公司名(法人):{$faren}
聯絡地區:{$address}
電話號碼:{$phone}
電子郵件:{$email}"; //sendmail($to,$sender,$subject,$body,$mailtype); ?>
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.