Well I’ll show you the way I did using gmail, Phpmailer and Wampserver.
1st enable the ssl_module
in apache. To Enable open the file httpd.conf
apache and look for the following line in the file #LoadModule ssl_module modules/mod_ssl.so
, remove the sign #
to enable.
2º Enable the following extensions in php.ini php_openssl
, php_sockets
and php_smtp
(if you do), in my case you do not. To enable extensions look for them in php.ini and remove the ;
front. Extensions are like this in php.ini ;extension=php_openssl.dll
, ;extension=php_sockets.dll
.
3rd Download Phpmailer on Github, unpack it and take the following classes:
![inserir a descrição da imagem aqui](https://i.stack.imgur.com/oTmQ3.jpg)
4º Encode.
require_once('class.phpmailer.php'); //chama a classe de onde você a colocou.
$mail = new PHPMailer(); // instancia a classe PHPMailer
$mail->IsSMTP();
//configuração do gmail
$mail->Port = '465'; //porta usada pelo gmail.
$mail->Host = 'smtp.gmail.com';
$mail->IsHTML(true);
$mail->Mailer = 'smtp';
$mail->SMTPSecure = 'ssl';
//configuração do usuário do gmail
$mail->SMTPAuth = true;
$mail->Username = '[email protected]'; // usuario gmail.
$mail->Password = 'suasenhadogmail'; // senha do email.
$mail->SingleTo = true;
// configuração do email a ver enviado.
$mail->From = "Mensagem de email, pode vim por uma variavel.";
$mail->FromName = "Nome do remetente.";
$mail->addAddress("[email protected]"); // email do destinatario.
$mail->Subject = "Aqui vai o assunto do email, pode vim atraves de variavel.";
$mail->Body = "Aqui vai a mensagem, que tambem pode vim por variavel.";
if(!$mail->Send())
echo "Erro ao enviar Email:" . $mail->ErrorInfo;
The first time I ran the above code returned me the following error:
SMTP Error: Could not authenticate
.
To resolve it I went in my email and found the following gmail message.
![inserir a descrição da imagem aqui](https://i.stack.imgur.com/TXaZy.jpg)
i.e., gmail blocked my connection attempt from localhost.
to avoid this mistake security settings of gmail and went on the
I checked the settings and activated as in the image below
![inserir a descrição da imagem aqui](https://i.stack.imgur.com/Pe6Kd.jpg)
and tried to resend the email from localhost again, sent it to myself.
![inserir a descrição da imagem aqui](https://i.stack.imgur.com/KTUuq.jpg)
and now I’ve sent it to another account of mine.
![inserir a descrição da imagem aqui](https://i.stack.imgur.com/yl4VI.jpg)
That was the way I did to send email through localhost.
OBS:
I’m using Wampserver, I think it works on any other server, just know where the server puts the file httpd
of the apache and the php.ini
, and enable modules and extensions.
OBS 2:
Phpmailer classes go in your project.
My answer was based on this tutorial.
worked, thanks! D
– Murilo Melo
good, for nothing
– user28266