简体   繁体   中英

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. q190sm41239770pfb.51 - gsmtp in C:\\wamp64\\www\\phpMailer\\mail.php on line 4

FYI: I am working on Netbeans with WAMP server on Windows 10, 64 bit OS.

You have to make sure your PHP installation has SSL support, check for presence of "openssl" section in the output from phpinfo() .

Then set the following settings in your 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() . It's a very basic function. You should use an industrial-strength SMTP library instead if you want to send mail. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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