I have a php code that works fine. I want to send an email to the admin saying user - A
has made an request. When I check the email, it shows user -
. It does not show the username.
THE PHP CODE:
<?php
require 'PHPMailerAutoload.php';
$username = $_SESSION ["username"];
function leave_mail($user, $message){
//Some connection and credentials for the gmail
$username = $_SESSION ["username"];
$mail = new PHPMailer;
leave_mail($username, "Your message has been sent to the <b>admin.</b>");
leave_mail('[email protected]', 'This message is to notify that you have a <b>new leave request</b> from <i><b>USER - <?php echo $username;?></b></i>');
?>
Please help!
leave_mail('[email protected]', 'This message is to notify that you have a <b>new leave request</b> from <i><b>USER - ' . $username . '</b></i>');
That is because what you are writing is already php code. So 'xxx' . $username . 'yyy'
is a string concat
in php.
When to use <?php xxx; ?>
? When you are writing a .php
file, you are defaultly writing html code. So when you want to write php, use it.
Example:
<html>
<body>
<div>hello i am html</div>
<?php for($i=0;$i<5;++$i)echo 'Hey this is php code'; ?>
</body>
</html>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments