0

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.

Amit Mhaske
  • 471
  • 5
  • 10
  • Possible duplicate of [Must issue a STARTTLS command first](http://stackoverflow.com/questions/10509699/must-issue-a-starttls-command-first) – Panda Dec 26 '16 at 11:31
  • 2
    try using a class like phpmailer so you can set the login details (SMTPAuth)... – John Mc Murray Dec 26 '16 at 12:02
  • Possible duplicate of [Can't send email with php mail function on windows 8](http://stackoverflow.com/questions/30610387/cant-send-email-with-php-mail-function-on-windows-8) – Protomen Dec 29 '16 at 18:36

1 Answers1

1

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.

Bud Damyanov
  • 30,171
  • 6
  • 44
  • 52