0

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";
}
?>
2
Contributors
1
Reply
17
Views
4 Years
Discussion Span
Last Post by cereal
1

Currently it runs twice. Change line 10 to:

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

And line 13 to:

if($sent === TRUE)
{
    # success
}
else
{
    # failure
}
Votes + Comments
Ok, Thank You. It now is sent once.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.