0
<?php
$targetEmail = 'myemail@gmail.com';
$subject = 'Sending e-mails from PHP is fun!';
$message = 'Do you agree?';

mail($targetEmail, $subject, $message);
echo mail(); //I use this to see the error
?>

I've already set that variable but when I echo it, it said Warning: mail() expects at least 3 parameters, 0 given And I'm not yet receiving the email

Noobster
  • 93
  • 11
  • I don't understand, that is just the answer from some question here in stackoverflow. – Noobster Jun 23 '16 at 03:27
  • `echo mail(); //I use this to see the error` is actually calling the mail function again and not outputting the result of `mail($targetEmail, $subject, $message);`. Check my answer. – Osama Sayed Jun 23 '16 at 03:30
  • Yes, it returns true, but I'm not receiving the email – Noobster Jun 23 '16 at 03:31

3 Answers3

0

You should do

<?php
$targetEmail = 'myemail@gmail.com';
$subject = 'Sending e-mails from PHP is fun!';
$message = 'Do you agree?';

$mail = mail($targetEmail, $subject, $message);
echo $mail;
Riad Loukili
  • 119
  • 8
0

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;
Osama Sayed
  • 1,993
  • 15
  • 15
0

Try something like this

 <?php
    $to = 'myemail@gmail.com';
    $subject = 'Sending e-mails from PHP is fun!';
    $message = 'Do you agree?';
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

    if(mail($to, $subject, $message ,$headers)){
        echo "successfully  mailed";
    }
    else{
        echo "Failure";
    }

    ?>

It works fine..!