欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

经过STMP发邮件,这段代码错在哪

程序员文章站 2024-04-02 19:48:28
...
通过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' => '',    'Date' => date( 'r' ),    '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); ?>
经过STMP发邮件,这段代码错在哪

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频