1
I have a form in html that the user will enter the name, email, subject and message, considering that the user will be able to type email from Hotmail, gmail, etc..., and when you confirm I am using the php code below to try to send the message to my email, using the PHP Mailer
, but the following error occurs:
SMTP Error: The following Recipients failed
I realized that this error occurs only when the $mail->From
is from Hotmail. If I put the same email of $mail->Username
error does not occur and sends the email normally.
I’ve researched and tried practically all the alternatives that indicate on the Internet but none of them worked, could anyone give me an idea of where the problem might be? maybe I’m not on the right track and would like to know if it is possible to send an email from any domain to my company email ?
<?php
require('phpmailer/PHPMailerAutoload.php');
require('phpmailer/class.phpmailer.php');
require('phpmailer/class.smtp.php');
require('phpmailer/class.pop3.php');
$to = "[email protected]"; // this is your Email address
$name = $_POST['nmContato'];
$from = $_POST['email']; // this is the sender's Email address
$subject = $_POST['assunto'];
$message = $name . " enviou a mensagem:" . "\n\n" . $_POST['txt_contato'];
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet="UTF-8";
$mail->Debugoutput = 'html';
$mail->Host = 'email-ssl.com.br';
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = true;
$mail->IsHTML(true);
$mail->Username = '[email protected]';
$mail->Password = 'senhadoemail';
$mail->From = $from; //o erro ocorre quando esse valor é [email protected]
$mail->FromName = $name;
$mail->AddAddress($to);
$mail->Subject = $subject;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->Body = $message;
$mail->SMTPDebug = 1;
if(!$mail->Send()){
echo 'Mailer Error: ' . $mail->ErrorInfo;
}else{
echo 'Message has been sent';
}
?>
<form class="form-horizontal" action="email.php" method="post" id="formContato">
<div class="form-group form-group-lg">
<label class="col-sm-3 control-label" for="nmContato">Nome</label>
<div class="col-sm-8" id="div_nmContato">
<input class="form-control" type="text" name="nmContato" id="nmContato">
</div>
</div>
<div class="form-group form-group-lg">
<label class="col-sm-3 control-label" for="email">Email</label>
<div class="col-sm-8" id="div_email">
<input class="form-control" type="text" name="email" id="email">
</div>
</div>
<div class="form-group form-group-lg">
<label class="col-sm-3 control-label" for="assunto">Assunto</label>
<div class="col-sm-8" id="div_assunto">
<input class="form-control" type="text" name="assunto" id="assunto">
</div>
</div>
<div class="form-group form-group-lg">
<label class="col-sm-3 control-label" for="txt_contato">Mensagem</label>
<div class="col-sm-8" id="div_mensagem">
<textarea id="txt_contato" name="txt_contato" class="form-control" rows="5"></textarea>
</div>
</div>
<button id="btnContato" type="submit" name="submit" class="btn btn-primary" style="margin-left:149px;">Enviar</button>
<button type="button" class="btn btn-primary" id="btn_limpa_contato">Limpar</button>
</form>
I believe that for from ser @Hotmail you must use the Hotmail authentication: https://answall.com/a/200541/3635
– Guilherme Nascimento
Related: https://answall.com/questions/99443/phpmailer-functionalcom-gmail-mas-n%C3%A3o-com-Hotmail-live
– Marcelo de Andrade
is not a duplicate, I researched all these questions before publishing here, I tried @Guilhermenascimento but it did not work
– Thiago Friedman
@Guilhermenascimento SMTP ERROR: Password command failed, the problem is that so, this page that sends the email, is the Contact page of the company website, so I would like you to accept any email domain, and send it to the company email, if this is impossible with phpmailer, I could orient myself with another component
– Thiago Friedman
I must have done cat by hare in dialing, @Guilhermenascimento. But already attached the second link I posted.
– Marcelo de Andrade
@Guilhermenascimento I will attach an image of the form and try to make it clearer what I want to do
– Thiago Friedman
@Guilhermenascimento did the editing explaining the problem better and includes html
– Thiago Friedman
Ready, responded to
– Guilherme Nascimento