简体   繁体   English

如何使用PHP和WAMP发送电子邮件

[英]How To send Email using PHP & WAMP

I am using this simple code. 我正在使用这个简单的代码。

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: itsthelucifer@gmail.com" . "\r\n";
mail("you@yourdomain.com","test subject","test body",$headers);

But even this simple code is not running. 但是,即使这个简单的代码也没有运行。 It's giving me error as 这给我错误

Warning: mail(): SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. 警告:mail():SMTP服务器响应:530 5.7.0必须首先发出STARTTLS命令。 q190sm41239770pfb.51 - gsmtp in C:\\wamp64\\www\\phpMailer\\mail.php on line 4 q190sm41239770pfb.51-第4行的C:\\ wamp64 \\ www \\ phpMailer \\ mail.php中的gsmtp

FYI: I am working on Netbeans with WAMP server on Windows 10, 64 bit OS. 仅供参考:我正在Windows 10(64位操作系统)上使用WAMP服务器的Netbeans。

You have to make sure your PHP installation has SSL support, check for presence of "openssl" section in the output from phpinfo() . 您必须确保您的PHP安装具有SSL支持,在phpinfo()的输出中检查是否存在“ openssl”部分。

Then set the following settings in your PHP.ini : 然后在您的PHP.ini设置以下设置:

ini_set("SMTP","ssl://your.mailserver.uri");
ini_set("smtp_port","465"); //Put your server port number

In general, do not use PHP's build-in mail() . 通常,不要使用PHP的内置mail() It's a very basic function. 这是一个非常基本的功能。 You should use an industrial-strength SMTP library instead if you want to send mail. 如果要发送邮件,则应改用具有行业实力的SMTP库。 The build-in mail() just does not support TLS ( Transport Layer Security and its predecessor, Secure Sockets Layer (SSL), both frequently referred to as "SSL", are cryptographic protocols that provide communications security over a computer network), use PHPMailer or similar package instead. 内置mail()仅不支持TLS(通常被称为“ SSL”的传输层安全性及其前身安全套接字层(SSL)是可通过计算机网络提供通信安全性的加密协议),请使用而不是PHPMailer或类似的软件包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM