When you do echo mail();
it is calling the function mail()
again but you are not passing any variables to it. Try:
$mail = mail($targetEmail, $subject, $message);
echo $mail;
However, according to the mail() documentation; the function accepts:
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
But you have to set-up the sender email in the $additional_headers variable to be able to send the email. Try this:
$targetEmail = 'myemail@gmail.com';
$subject = 'Sending e-mails from PHP is fun!';
$message = 'Do you agree?';
$headers = "From: your-email@example.com" . "\r\n" .
"CC: somebodyelse@example.com";
$mail = mail($targetEmail, $subject, $message, $headers);
echo $mail;