Hi, I have a really simple mailing script.It works, but it sends the message twice. How do I send the mail once.

<?php
$email = 'example@domain.com';
$subject = 'MESSAGE FROM DOMAIN!';
$message = 'The Message Was Successfully Sent!';
$headers = 'From: noreply@domain.com' . "\r\n" .
    'Reply-To: reply@domain.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();


mail($email, $subject, $message, $headers);
?>
<?php
if(@mail($email, $subject, $message, $headers))
{
  echo "Mail Sent Successfully";
}else{
  echo "Mail Not Sent";
}
?>

Currently it runs twice. Change line 10 to:

$sent = mail($email, $subject, $message, $headers);

And line 13 to:

if($sent === TRUE)
{
    # success
}
else
{
    # failure
}
commented: Ok, Thank You. It now is sent once. +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.