Mail () function error - Must issue a STARTTLS command first

0

Well, I've researched the error, many users said that ssl:// to smtp.google.com or tls:// to imap.google.com should be added, using ports 465 (or 993 as an alternative) and 587 respectively. I tested a number of user configurations of the stackoverflow itself, none of them could stop this problem.

php.ini

[mail function]
SMTP=imap.gmail.com
smtp_port=587

sendmail_from = [email protected]

mail.add_x_header=On

sendmail.ini

smtp_server=imap.gmail.com

smtp_port=587

smtp_ssl=auto

error_logfile=error.log

[email protected]
auth_password=xxxxxxx

sending script

<?php

$nome = $_POST["nome"];
$assunto = $_POST["assunto"];
$mensagem = $_POST["mensagem"];
$mensagem = wordwrap($mensagem, 70);
$mensagem = str_replace("\n.", "\n..", $mensagem);
$email = $_POST["email"];
$telefone = $_POST["telefone"];
#Montagem do e-mail
$from = $email;
$to = "[email protected]";
$subject = $assunto;
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: {$from}" . "\r\n";
$headers .= "To: {$to}" . "\r\n";
$headers .= "X-Mailer: " . phpversion();
$message = "<p>{$nome}</p><br />
            <p>{$email}</p><br />
            <p>{$telefone}</p><br />
            <br />
            <p>{$assunto}</p><br />
            <p>{$mensagem}</p>";
mail($to, $subject, $message, $headers);

Warning returned:

mail(): SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. b62-v6sm6183858qkj.48 - gsmtp in C:\xampp\htdocs\willy\contact_form.php on line 25

How can I fix the problem?

    
asked by anonymous 20.08.2018 / 19:24

1 answer

1

This is quite wrong:

imap.gmail.com

Imap is to receive and not to send emails, they are totally different protocols, probably the correct one is:

SMTP="ssl://smtp.gmail.com";
smtp_port=465

As quoted in this answer: link or:

SMTP="tsl://smtp.gmail.com";
smtp_port=587

If SSL does not work (I do not know how Gmail is)

Note that no php.ini can not contain spaces in the values:

sendmail_from = [email protected]

The correct one would be:

[email protected]

But it's important to keep in mind that you need to have active SSL in php via php.ini , so take the; front of the extension

If it's windows (php up to version 7.1):

;extension=php_openssl.dll

It should look like this:

extension=php_openssl.dll

If it is linux or mac (php up to version 7.1):

;extension=openssl.so

It should look like this:

extension=openssl.so

If it is PHP7.2 independent of windows, linux or mac should look like this:

;extension=openssl

It should look like this:

extension=openssl

After editing the php.ini it is necessary to restart your HTTP server, usually apache.

    
20.08.2018 / 19:39