Jump to content

Archived

This topic is now archived and is closed to further replies.

lional

Help with mail() function

Recommended Posts

I am busy writing a mail script. What I would like to do is give a confirmation message if the mail was sent successfully, or a generic message if it was unsuccessful.

Here is what my script looks like:

<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title>Easy Security</title>

</head>
<body>

<?php
$firstname = $_POST['firstname'];
$surname = $_POST['surname'];
$telephone = $_POST['telephone'];
$cell = $_POST['cell'];
$email = $_POST['mail'];
$subject = $_POST['subject'];
$message = $_POST['message'];
?>
<?
include 'includes/conn_db.php';
$query1 = "INSERT INTO clients (firstname, surname, telephone, cell, mail) VALUES ('$firstname', '$surname', '$telephone', '$cell', '$email')";
$result1 = @mysql_query ($query1);
$query_count = "SELECT * from bulkmail WHERE mail = '$email'";
$result_count = mysql_query($query_count);
$num_records = @mysql_num_rows($result_count);
if ($num_records == 0) {
$query2 = "INSERT INTO bulkmail (firstname, surname, telephone, cell, mail) VALUES ('$firstname', '$surname', '$telephone', '$cell', '$email')";
$result2 = @mysql_query ($query2);
}
?>
<?
$adminmail = "info@it-people.co.za";
?>



<?
// Recipients. You can send it to more than 1 person!
$to = "$adminmail" ; // note the comma

?>
<?
// This is the email subject
$my_subject = "$subject";
?>


<? // Message
$my_message = <<<MESSAGE
First Name: $firstname<br>Surname: $surname<br>Telephone: $telephone<br>Cellphone: $cell<p>$message
MESSAGE;
?>
<?
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: $email";
?>


<?
// And now mail it!
mail($to, $my_subject, $my_message, $headers);
?>


</body>
</html>

Any help will be appreciated

Thanks

Lional

Share this post


Link to post
Share on other sites
Try this
[code]if (mail($to, $my_subject, $my_message, $headers))
     {
            echo 'Email sent successfully';
          }
          else
      {
        echo 'Could not send email.';
      }[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.