echo php variable in javascript alert code example
Example 1: php echo alert js
echo '<script type="text/javascript">alert("Data has been submitted to ' . $to . '");</script>';
Example 2: alert a php variable
echo '<script type="text/javascript">alert("'.$error.'");</script>';