0

so I have used the Advanced option from the http://php-login.net/ and this creates an advanced login PHP script on my site. Allowing visitors to signup, and create an account. The way it works is visitors fill out the sign up form, and a verification email is sent. This email is a simple text email, and is defined via PHP's define() method. The code for the define is;

define("EMAIL_VERIFICATION_CONTENT", "Please click on this link to activate your account:");

And here's the code that sends the email;

    /*
 * sends an email to the provided email address
 * @return boolean gives back true if mail has been sent, gives back false if no mail could been sent
 */
public function sendVerificationEmail($user_id, $user_email, $user_activation_hash)
{
    $mail = new PHPMailer;

    // please look into the config/config.php for much more info on how to use this!
    // use SMTP or use mail()
    if (EMAIL_USE_SMTP) {
        // Set mailer to use SMTP
        $mail->IsSMTP();
        //useful for debugging, shows full SMTP errors
        //$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
        // Enable SMTP authentication
        $mail->SMTPAuth = EMAIL_SMTP_AUTH;
        // Enable encryption, usually SSL/TLS
        if (defined(EMAIL_SMTP_ENCRYPTION)) {
            $mail->SMTPSecure = EMAIL_SMTP_ENCRYPTION;
        }
        // Specify host server
        $mail->Host = EMAIL_SMTP_HOST;
        $mail->Username = EMAIL_SMTP_USERNAME;
        $mail->Password = EMAIL_SMTP_PASSWORD;
        $mail->Port = EMAIL_SMTP_PORT;
    } else {
        $mail->IsMail();
    }

    $mail->From = EMAIL_VERIFICATION_FROM;
    $mail->FromName = EMAIL_VERIFICATION_FROM_NAME;
    $mail->AddAddress($user_email);
    $mail->Subject = EMAIL_VERIFICATION_SUBJECT;

    $link = EMAIL_VERIFICATION_URL.'?id='.urlencode($user_id).'&verification_code='.urlencode($user_activation_hash);

    // the link to your register.php, please set this value in config/email_verification.php
    $mail->Body = EMAIL_VERIFICATION_CONTENT.' '.$link;

    if(!$mail->Send()) {
        $this->errors[] = MESSAGE_VERIFICATION_MAIL_NOT_SENT . $mail->ErrorInfo;
        return false;
    } else {
        return true;
    }
}

Now, everything works as it should, however, I wish to send a HTML email, and not a simple text email.

How would I go about doing this, altering the code I already have?

  • 3
    I think is what you are looking for: http://stackoverflow.com/questions/11140263/phpmailer-sending-html-code (PHPMailer isHTML option). – Maximus2012 Feb 16 '16 at 21:54
  • @Maximus2012 Hm, okay so I just add that one code in my code, and then HTML should work? Where would I use the HTML code then? Thanks for the reply! – NewGuyOnTheBlock Feb 16 '16 at 21:59
  • I think that flag in PHPMailer should take care of most of the HTML. Please refer to the PHPMailer documentation for specific use-cases of HTML email. – Maximus2012 Feb 16 '16 at 22:04
  • @Maximus2012 Thank you for the link! I can't quite get it right however! I have used the isHTML code, and added some HTML elements in my code (Specifically the `$mail->body` bit, but it doesn't show the HTML elements at all in the email. – NewGuyOnTheBlock Feb 17 '16 at 00:28
  • Are you sure that there are HTML elements in your message body ? Try adding some simple elements like `

    ` and `
    ` maybe ?
    – Maximus2012 Feb 17 '16 at 15:00
  • Yes, I am sure that I am using HTML elements, I'll paste some more code of what I am currently doing. – NewGuyOnTheBlock Feb 17 '16 at 15:56
  • There are plenty of guides and tutorials online on how to do that. – Maximus2012 Feb 17 '16 at 16:03
  • It works now! Miracle! Thanks a lot for the help :) – NewGuyOnTheBlock Feb 17 '16 at 16:04

0 Answers0