"465", "username" => "", //用户名">
时间:2021-07-01 10:21:17 帮助过:7人阅读
"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; } ?>
debug = true; //是否开启调试,只在测试程序时使用,正式使用时请将此行注释 $to = "收件人的邮件地址"; //收件人 //准备使用的邮箱 $subject = "咨询"; $body=" 咨询人:{$firstname}.{$familyname}
咨询人名字拼音:{$firstnamepy}.{$familynamepy}
咨询人性别:{$sex}
咨询种类:{$zixun1}
咨询内容:{$zixun}
公司名(法人):{$faren}
联络地区:{$address}
电话号码:{$phone}
电子邮件:{$email}"; //sendmail($to,$sender,$subject,$body,$mailtype); ?>