I am using a php script that send email automatically to a logged in user when he access some pages in his account. The client table has two different emails in two different columns (mail1 and mail2), mail1 is used as username. The script can send to the primary email (the email he used to login), but can not send to his secondary email (mail2). I want the email to be sent to the his second email address stored in the other database column, not to the one he used to login.
Here is my code
<?php
if(isset($_SESSION["mail1"]))
{
$to = $_SESSION["mail1"];
$subject = 'the subject';
$message = 'hello';
$headers = 'From: my@example.com' . "\r\n" .
'Reply-To: my@dexample.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
echo 'Email Sent.';
}
?>
I works like this but when I change $to = $_SESSION["mail1"] to
$to = $`$_SESSION["mail2"] it won't work, and i want it to work with mail2
How to make it send the email to mail2?