Description: I’m working on a PHP script that should automatically click an email link using JavaScript. The code works fine in a separate test.php file, but in process.php, the JavaScript doesn’t execute. Below is the relevant code:
<?php
include_once 'libs/load.php';
if (isset($_POST['command'])) {
$command = trim($_POST['command']);
handleCommand($command);
}
function handleCommand($command)
{
switch ($command) {
case 'email':
$email = "[email protected]";
echo "<html><body>";
echo "<a id="emailLink" href="mailto:$email" style="color: rgb(5, 206, 145);">$email</a>";
echo "<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
console.log('JavaScript is running');
alert('JavaScript is running');
document.getElementById('emailLink').click();
});
</script>";
echo "</body></html>";
break;
default:
echo "---n";
echo "Unknown command: $commandn";
echo "---";
break;
}
}
?>