SMTP Error: The following Recipients failed from Hotmail to enterprise

Asked

Viewed 931 times

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> 

inserir a descrição da imagem aqui

  • 1

    I believe that for from ser @Hotmail you must use the Hotmail authentication: https://answall.com/a/200541/3635

  • 1

    Related: https://answall.com/questions/99443/phpmailer-functionalcom-gmail-mas-n%C3%A3o-com-Hotmail-live

  • is not a duplicate, I researched all these questions before publishing here, I tried @Guilhermenascimento but it did not work

  • @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

  • I must have done cat by hare in dialing, @Guilhermenascimento. But already attached the second link I posted.

  • @Guilhermenascimento I will attach an image of the form and try to make it clearer what I want to do

  • @Guilhermenascimento did the editing explaining the problem better and includes html

  • Ready, responded to

Show 3 more comments

1 answer

3

Many lodgings block "make up" the sender, this to prevent SPAMMERS make use of this practice, so there will be no way to connect to a specific SMTP and change the to:, the server will "deny"

By the settings I assume it is Locaweb, as I recall they also have this restricted policy to prevent Spams:

$mail->Host = 'email-ssl.com.br';
$mail->Port = 465;  
$mail->SMTPSecure = 'ssl';

It doesn’t mean that you are a SPAMMER, it just means that spammers make use of it and so it is better to block everyone.

What you can do is use the Reply-To: instead of To:

$name = $_POST['nmContato'];    
$from = $_POST['email'];

$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->AddReplyTo($from, $name); //AQUI vai o reply-to:

$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;

Extra note

When sending to the production server remove this line $mail->SMTPDebug = 1;, the data that are displayed chance any error occurs may be sensitive.

  • thanks for your attention Guilherme, but still the same error, I realized that the error does not show the email of the Hotmail and yes [email protected], SMTP ERROR: RCPT TO command failed: 504 5.5.2 <root@localhost>: Sender address Rejected: need Fully-Qualified address

  • 1

    @Thiagofriedman is not the same error, the message is fully different, I’ll try to adjust and I’ll let you know.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.