Sending link by email with Phpmailer

Asked

Viewed 2,147 times

0

I’m having a hard time sending one link with references, by email, with Phpmailer.

Can someone help me?

    require 'phpmailer/PHPMailerAutoload.php';

    $mail = new PHPMailer;
    $mail->IsHTML(true);
    $titulo = "Parabéns! Surgiu alguém interessado no(a) ".$partner_name;
    $texto2 = "<html>";
    $texto = "Parabéns! Surgiu um pretendente para o(a) ".$partner_name.". Para ver o pretendente, clique no link baixo. <br> ".$link;
    $mail->setFrom('[email protected]', 'PetsMatch');
    $mail->addReplyTo('[email protected]', 'First Last');
    $mail->addAddress($ownerEmail, $ownerName.' '.$ownerLastName);
    //Set the subject line
    $mail->Subject = utf8_decode($titulo);
    //$mail->CharSet = 'iso-8859-1';
    $mail->Body = "
    <p>Parabéns! Surgiu um pretendente para o(a) ".$partner_name.". Para ver o pretendente, clique no link baixo. <br> <a href='<a href='https://www.eeee.com.br/php/pares.php?type=".$type."&breed=".$breed."&sex=".$sex."&city=".$city."&state=".$state.">ver</a>;
    </p>";
    //$mail->msgHTML(utf8_decode($texto2));
    //Replace the plain text body with one created manually
    $mail->AltBody = 'This is a plain-text message body';
    //Attach an image file
    //$mail->addAttachment('images/phpmailer_mini.png');

    //send the message, check for errors
    if (!$mail->send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        echo "Aviso de interesse enviado!";
    }
  • Post your code so it’s easier to help you. (Remove any confidential information first)

  • And paste what comes to the email

  • @Kaduamaral, I put my code.

1 answer

1


Apparently it’s a mistake of syntax html. Repair your code:

<p>Parabéns! Surgiu um pretendente para o(a) ".$partner_name.". Para ver o pretendente, clique no link baixo. <br> 
<a href='<a href='https://www.eeee.com.br/php/pares.php?type=".$type."&breed=".$breed."&sex=".$sex."&city=".$city."&state=".$state.">ver</a>;
</p>

Has two tag openings a one inside the other, in this part:

<a href='<a href=

Change to:

$mail->Body = "<p>Parabéns! Surgiu um pretendente para o(a) {$partner_name}. ".
              "Para ver o pretendente, clique no link baixo. <br> ".
              "<a href='https://www.eeee.com.br/php/pares.php".
              "?type={$type}&breed={$breed}&sex={$sex}&city={$city}&state={$state}'>ver</a>".
              "</p>";

Always try to keep a good format in your code, avoiding very long lines, so it is easier to find errors.

  • I made the modification and you sent it, but I am receiving the email like this: "Congratulations! A suitor has appeared for the (a) Bizucão. To see the suitor, click on the link below. <a href='https://www.eeee.com.br/php/pares.php?type=1&breed=2&sex=2&city=Porto_Alegre&state=RS>ver</a></p>" And not just the word "see" and the format or appearance of the link, understand?

  • now it worked! Where exactly was the error? What was that closing quote?

  • I already found the quote you say was missing. I analyzed the code, put the two, side by side and analyzed... Something else, instead of putting the whole url, straight, I can’t put it inside a variable and color only this variable in the body of the email? You understand me?

  • Yes you can @Gustavosevero, as I did in the variables $type, $breed can be made another. Put everything that is in the href in a variable $link = "https://www.eeee..." and put it in place href='{$link}'. ;)

  • Thank you for your attention @Kaduamaral. E why you used "{ }" in the variables?

  • 1

    This is a rag for @Gustavosevero .... Basically to "help" PHP identify where the variables are within a string. Works only on strings made with double quotes ("")

Show 1 more comment

Browser other questions tagged

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