0

I am using a html email template for my account verification via email

so in my "register_session.php" i have integrated the PHPMailer and all in order to send an email to user. I have the following code:

 $email = $_REQUEST['email']; //to
 $subject = 'Account Verification';
 $message = file_get_contents('../emailhtml.php', FILE_USE_INCLUDE_PATH);
 $header = 'From:Test' . "\r\n" .
                'Content-type: text/html; charset=iso-8859-1\r\n'; //set FROM HEADER
 mail ($email, $subject, $message, $header);

In my $message I used file_get_contents to retrieve the html code in emailhtml.php. Inside of emailhtml.php, I have my html & css code. See below:

<?php
include("../web/Includes/database_master_mysql.php");
$database_master = new DatabaseMaster();
$email = $_GET['email'];
$code = $_GET['code'];
?>

<html>
<head></head>
<body>

<table border="0" cellpadding="0" cellspacing="0" width="50%" class="emailButton" style="background-color: #3498DB;">
    <tr>
        <td align="center" valign="middle" class="buttonContent" style="padding-top:15px;padding-bottom:15px;padding-right:15px;padding-left:15px;">
            <a style="color:#FFFFFF;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:20px;line-height:135%;" href=" <?php echo'http://localhost/web/web/emailactivate.php?email='.$email.'&code='.$code.'';?> ">Confirmation</a>
        </td>
    </tr>
</table>

</body>
</html>

I didn't put all the code because what my concern is in my href tag I wanted to redirect user upon clicking the button in their email to http://localhost/web/web/emailactivate.php?email='.$email.'&code='.$code.'

but what shows up in mine is: http://localhost/web/web/emailactivate.php?email%20=%3C?php%27.$email.%27?%3E&code=%3C?php%27.$code.%27%20?%3E

I'm not really knowledgeable in PHP so it would mean a world to me if you'll help me. Thank you.

Tiffany
  • 609
  • 12
  • 26
cara jenner
  • 21
  • 1
  • 6
  • maybe change $message = file_get_contents('../emailhtml.php to $message = file_get_contents('../emailhtml.php?email='.$_GET['email'].' etc.... – Funk Doc May 23 '18 at 17:41
  • What you're looking at is called URL encoding. And you'll find a solution to your problem here: https://stackoverflow.com/questions/11140263/phpmailer-sending-html-code – icecub May 23 '18 at 17:42
  • Use URL Encode on building your string: http://php.net/manual/en/function.urlencode.php – statosdotcom May 23 '18 at 17:42
  • The code you're importing with `file_get_contents` won't get executed by PHP. You'll need to import it and replace the variables manually. – Dan May 23 '18 at 17:43

1 Answers1

0

First, move the php code from your emailhtml.php to register_session.php and only leave html code in there.

Then for your mail() function put it in a variable to so you know if the mail was sent or not.

include("../web/Includes/database_master_mysql.php");
$database_master = new DatabaseMaster();
$email = $_GET['email'];
$code = $_GET['code'];
//$email = $_REQUEST['email']; //don't need this line. it's already set from the url request above.
$subject = 'Account Verification';
$message = file_get_contents('../emailhtml.php', FILE_USE_INCLUDE_PATH);
$header = 'From:Test' . "\r\n" .
                'Content-type: text/html; charset=iso-8859-1\r\n'; //set FROM HEADER
$send=mail ($email, $subject, $message, $header);

if($send){
   //email was successfully sent, do something
} else {
   //email did not send, check logs for errors
}
Liquidchrome
  • 836
  • 4
  • 9