A possible solution to remove this would be to use Phpmailer to upload.
First download via Poser in your project folder (your use Composer):
composer require phpmailer/phpmailer
Or download the latest Release on: https://github.com/PHPMailer/PHPMailer/releases
If you downloaded the folder PHPMailer-5.2.14
in the folder that is your script, the folder structure should be something like:
./projeto
|---- enviaremail.php
|---- PHPMailer-5.2.14/
|---- PHPMailerAutoload.php
|---- ...
email.php:
<?php
require 'PHPMailer-5.2.14/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Pra depurar o código remova o // do começo
$mail->isSMTP(); // Define como SMTP
$mail->Host = 'smtp.exemplo.com'; // Endereço do SMTP
$mail->Port = 25; // Porta do SMTP
$mail->SMTPAuth = true; // Autenticação no SMTP
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'senha'; // SMTP password
//$mail->setFrom('[email protected]', 'Mailer'); //comentei esta linha pois o Gmail irá detectar se tentar alterar o "from", mas pode tentar
//Adiciona destinatários:
$mail->addAddress('[email protected]', 'Joe User'); // Adiciona destinatário
$mail->addAddress('[email protected]'); // Destinatário sem nome
$mail->addReplyTo('[email protected]', 'Information');
//Manda como cópia
$mail->addCC('[email protected]');
//Manda como cópia oculta
$mail->addBCC('[email protected]');
//Anexos se precisar
$mail->addAttachment('/var/tmp/file.tar.gz');
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');
//Habilita HTML
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Assunto';
$mail->Body = 'Mensagem <b>teste</b>';
$mail->AltBody = 'Mensagem em texto, alternativa ao HTML';
if(!$mail->send()) {
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Mensagem enviada';
}
If to use Gmail as "sender" you will have to unlock in Gmail settings, the settings to use your Gmail account to send emails is:
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// Se a rede não suportar SMTP sobre IPv6
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "[email protected]";
$mail->Password = "yourpassword";
For other problems see:
no, gmail even provided an explanation for this: https://support.google.com/mail/answer/1311182?hl=pt-BR
– Alan PS
I put an image
– Alan PS
use the gmail email!
– Alan PS
Okay, I get the problem, I edited my answer, please try it. I edited the title of the answer to make it a little more intuitive for other people who have the same problem to find your question ;)
– Guilherme Nascimento
I think you’re missing an important piece of information in the answers given so far: the additional parameter
-f
in case PHP is using sendmail, to precisely set the sending host.– Bacco
@Bacco did not know that this was necessary with SMTP, I will do a test only with
mail();
and Gmail, your comment seems an embryo of a response (as the bfavaretto would say)– Guilherme Nascimento
@Guillhermenascimento ended up posting a "minireply" for appearing a duplicate with the same problem.
– Bacco