Error: You must provide at least one recipient email address

Asked

Viewed 2,565 times

0

Colleagues.

I have a website where there are 02 forms. One for the traditional Contact Us and the other for resume submission. I am using Phpmailer. In Contact Us is working correctly, but in the other resume submission form, the following error appears: You must provide at least one recipient email address.

Follow the code below:

  include("includes/class.phpmailer.php");
        $mail = new PHPMailer();
        $mail->From = "[email protected]";
        $mail->FromName = "Currículo";
        $mail->AddAddress("[email protected]");
        $mail->IsHTML(true);
        $mail->AddAttachment($curriculo['tmp_name'],$curriculo['name']);
        $data = date("d/m/Y");
        $hora = date("H:i");
        $mensagemHTML = "mensagem";
  $mail->Subject = "Vaga enviada pelo site";
        $mail->Body = $mensagemHTML;

        $mail->ClearAllRecipients();
        $mail->ClearAttachments();

       if($mail->Send()){
           $mensagem = 'Seu curriculo foi enviada com sucesso!';
       }else{
           $mensagem = "Erro ao enviar. Se o erro persistir, entre em contato                 conosco!";
       }

The directory is correct, just like the email. Would anyone know why this error?

2 answers

1


I think the problem is:

    /// aqui você adiciona um recipient
    $mail->AddAddress("[email protected]");
    $mail->IsHTML(true);
    $mail->AddAttachment($curriculo['tmp_name'],$curriculo['name']);
    $data = date("d/m/Y");
    $hora = date("H:i");
    $mensagemHTML = "mensagem";
    $mail->Subject = "Vaga enviada pelo site";
    $mail->Body = $mensagemHTML;

    // aqui você apaga todos <<<<<<<<
    $mail->ClearAllRecipients();

Try commenting on this line above.

PS: the text is wrong. "Your resume has been successfully sent".

  • 1

    Bingo Michelle. That’s right. About the text, thank you too. How I copied from Contact Us "Your message has been sent successfully!" I didn’t notice that ;)

0

According to the error message you are not assigning any value in the property $mail->Addaddress(), although the code you posted is.

Before you run the Send() method of a var_dump in $mail to make sure you’ve actually assigned an address.

var_dump($mail);
    if($mail->Send()){
  • Hello Norivan. It’s really weird, because I’m passing the value on $mail->Addaddress(). I gave the var_dump. See: Object(Phpmailer)#1 (53) { ["Priority"]=> int(3) ["Charset"]=> string(10) "iso-8859-1" ["Contenttype"]=> string(9) "text/html" ["Encoding"]=> string(4) "8bit" ["Errorinfo"]=> string(54) "You must provide at least one recipient email address." ["From"]=> string(25) "[email protected]" ["Fromname"]=> string(23) "Resume" ["Sender"]=> string(0) "["Subject"]=> string(22) "Wave sent by site" ["Body"]=> string(466) "

  • Dude if you are passing the value even the class should be considering email that you are passing as invalid. Try using two valid and different addresses for From and Addaddress

  • The address is valid. It’s my Gmail. The email is not coming by a variable or via Post, but is fixed within $mail->Address(). This is what I find strange, because I’m using the same structure in Contact Us and it works perfectly.

Browser other questions tagged

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