'WampServer: Warning: mail(): SMTP server response: 530 5.7.0 Must issue a STARTTLS command first

I am having an issue with WampServer, I tried creating a contact form but it isn't working. BIOS stopped recognizing my 2GB RAM chip so my system thinks it's 32-bit instead of 64-bit. Here's the PHP error table:

( ! ) Warning: mail(): SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. 8sm9902426ioe.8 - gsmtp in C:\Users\miner\Desktop\Configuration Creator\www\contact\mail.php on line 10
Call Stack
#   Time    Memory  Function    Location
1   0.0004  245672  {main}( )   ..\mail.php:0
2   0.0004  246648  mail ( )    ..\mail.php:10

Here's my code:

contact.html

<form action="mail.php" method="POST">
    <input type="text" class="form-control" name="name" placeholder="Name">
    <div class="padded-bottom"></div>
    <input type="text" class="form-control" name="email" placeholder="Email">
    <div class="padded-bottom"></div>
    <input type="text" class="form-control" name="subject" placeholder="Subject">
    <div class="padded-bottom"></div>
    <textarea type="text" class="form-control no-resize paragraph" rows="8" name="message" placeholder="Message"></textarea>
    <div class="padded-bottom"></div>
    <button type="submit" class="btn btn-default">Submit</button> <button type="reset" class="btn btn-default">Clear Form</button>
</form>

mail.php

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$from = 'From: '. $name; 
$to = '[email protected]'; 
$subject = $subject;
$body = "From: $name\n Email: $email\n Message:\n $message";     
if (mail ($to, $subject, $body, $from)) { 
    echo '<p>Your message has been sent!</p>';
} else { 
    echo '<p>Something went wrong. Please manually <a href="mailto:[email protected]">email me</a> and include a screenshot/copy of the log above.</p>'; 
}
?>

and finally, php.ini

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = smtp.gmail.com
; http://php.net/smtp-port
smtp_port = 587

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = [email protected]

Sorry if it's a duplicate, my problem is different than others.



Solution 1:[1]

Try to change this

; http://php.net/smtp
SMTP = smtp.gmail.com
; http://php.net/smtp-port
smtp_port = 587

to this (variant #1):

; http://php.net/smtp
SMTP = ssl://smtp.gmail.com
; http://php.net/smtp-port
smtp_port = 465

or to this (variant #2):

; http://php.net/smtp
SMTP = tls://smtp.gmail.com
; http://php.net/smtp-port
smtp_port = 587

One of my variants should be OK for you.

But I don't recommend use mail() function all the more so with Wamp (sockets will be good solution).

UPDATE

Do you really use Gmail smtp-service with mail() or you post Gmail only for example? For using Gmail smtp-service you need authentication (password+username), but mail() function don't support it. You need write personal mail-function based on sockets or use ready-made solutions like hMailServer and send mail using this software (hMailServer creditnails should be write to php.ini).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1