经过STMP发邮件,这段代码错在哪
通过STMP发邮件,这段代码错在哪?
发不出邮件,也不返回错误提示。各位高手看看代码错在哪?
- PHP code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --><?php header( "content-type:text/html;charset=utf-8" ); $smtp = array( "url" => "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
<?php if($_SERVER["REQUEST_METHOD"]=="POST"){?> <?php //ok的邮箱发送。 include "smtp.class.php"; //$smtpserver = "SMTP.163.com"; //您的smtp服务器的地址 $smtpserver=""; $port =25; //smtp服务器的端口,一般是 25 //$smtpuser = ""; //您登录smtp服务器的用户名 //$smtppwd = ""; //您登录smtp服务器的密码 $mailtype = "HTML"; //邮件的类型,可选值是 TXT 或 HTML ,TXT 表示是纯文本的邮件,HTML 表示是 html格式的邮件 $sender = "{$email}"; //发件人,一般要与您登录smtp服务器的用户名($smtpuser)相同,否则可能会因为smtp服务器的设置导致发送失败 $smtp = new smtp($smtpserver,$port,false,$smtpuser,$smtppwd,$sender); //第三个值为false时,可匿名登录发送邮件,将$smtpuser、$smtppwd注释掉 //$smtp->debug = true; //是否开启调试,只在测试程序时使用,正式使用时请将此行注释 $to = "收件人的邮件地址"; //收件人 //准备使用的邮箱 $subject = "咨询"; $body=" 咨询人:{$firstname}.{$familyname}<br> 咨询人名字拼音:{$firstnamepy}.{$familynamepy}<br> 咨询人性别:{$sex}<br> 咨询种类:{$zixun1}<br> 咨询内容:{$zixun}<br> 公司名(法人):{$faren}<br> 联络地区:{$address}<br> 电话号码:{$phone}<br> 电子邮件:{$email}"; //<?php for($i=0;$i<count($zixun1);$i++) echo $zixun1[$i] $send=$smtp->sendmail($to,$sender,$subject,$body,$mailtype); ?> <div class="clear"> </div>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Both curl and Pythonrequests are powerful tools for sending HTTP requests. While curl is a command-line tool that allows you to send requests directly from the terminal, Python's requests library provides a more programmatic way to send requests from Python code. The basic syntax for converting curl to Pythonrequestscurl command is as follows: curl[OPTIONS]URL When converting curl command to Python request, we need to convert the options and URL into Python code. Here is an example curlPOST command: curl-XPOST https://example.com/api

To update the curl version under Linux, you can follow the steps below: Check the current curl version: First, you need to determine the curl version installed in the current system. Open a terminal and execute the following command: curl --version This command will display the current curl version information. Confirm available curl version: Before updating curl, you need to confirm the latest version available. You can visit curl's official website (curl.haxx.se) or related software sources to find the latest version of curl. Download the curl source code: Using curl or a browser, download the source code file for the curl version of your choice (usually .tar.gz or .tar.bz2

PHP8.1 released: Introducing curl for concurrent processing of multiple requests. Recently, PHP officially released the latest version of PHP8.1, which introduced an important feature: curl for concurrent processing of multiple requests. This new feature provides developers with a more efficient and flexible way to handle multiple HTTP requests, greatly improving performance and user experience. In previous versions, handling multiple requests often required creating multiple curl resources and using loops to send and receive data respectively. Although this method can achieve the purpose

From start to finish: How to use php extension cURL for HTTP requests Introduction: In web development, it is often necessary to communicate with third-party APIs or other remote servers. Using cURL to make HTTP requests is a common and powerful way. This article will introduce how to use PHP to extend cURL to perform HTTP requests, and provide some practical code examples. 1. Preparation First, make sure that php has the cURL extension installed. You can execute php-m|grepcurl on the command line to check

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

How to handle 301 redirection of web pages in PHPCurl? When using PHPCurl to send network requests, you will often encounter a 301 status code returned by the web page, indicating that the page has been permanently redirected. In order to handle this situation correctly, we need to add some specific options and processing logic to the Curl request. The following will introduce in detail how to handle 301 redirection of web pages in PHPCurl, and provide specific code examples. 301 redirect processing principle 301 redirect means that the server returns a 30

In Linux, curl is a very practical tool for transferring data to and from the server. It is a file transfer tool that uses URL rules to work under the command line; it supports file upload and download, and is a comprehensive transfer tool. . Curl provides a lot of very useful functions, including proxy access, user authentication, ftp upload and download, HTTP POST, SSL connection, cookie support, breakpoint resume and so on.
