troubleshooting Question

mail() function having strange results

Avatar of brad_tho
brad_tho asked on
PHP
3 Comments1 Solution214 ViewsLast Modified:
Hi, I have a contact form which is giving me strange results.

the form sends 2 emails: 1 to the person who lodged it as a confirmation, and 1 to either the site ppl or the webmaster.

the 2 emails are slightly different.

for some reason, whenever its supposed to to go the webmaster, it does, but the person who submitted the form gets 2 emials - one of each kind...weird.
here's all of the relevant code (i think)!


<?php

//functions to check contents of fields, return true or false


function send_original_mail ($mail_to, $mail_name, $mail_from, $mail_subject, $mail_message) {
      $time = strftime("%I:%M %p");
      $date = strftime("%A, %d/%m/%y");
      if ($mail_to == "webmaster") {
            $mail_address = "webdesign@tabbagong.com";
      }
      elseif ($mail_to == "owner") {
            $mail_address = "bradley@tabbagong.com";
      }
      $full_message = "This email sent to you from the Supporting Mobile Learning online form.\r\n\r\nName: " . $mail_name . "\r\nEmail: " . $mail_from . "\r\nSubject: " . $mail_subject . "\r\nMessage: " . $mail_message . "\r\nSent: " . $time . " on " . $date;
      $mail_headers = 'To: ' . $mail_name . " <" . $mail_from . ">\r\n" .      
                              'From: ' . $mail_name . " <" . $mail_from . ">\r\n" .
                                 'Reply-To: ' . $mail_name . " <" . $mail_from . ">\r\n";
      if ((mail($mail_address, $mail_subject, $full_message, $mail_headers)) == 1) {
            return true;
      }
      else { return false; }
}
function send_confirm_mail ($mail_name, $mail_from, $mail_subject, $mail_message) {
      $time = strftime("%I:%M %p");
      $date = strftime("%A, %d/%m/%y");
      $full_message = "Dear " . $mail_name . ",\r\n\r\nThank you for your enquiry. We will endevour to reply to you as soon as we can.\r\nYour enquiry is attached below.\r\n\r\nName: " . $mail_name . "\r\nEmail: " . $mail_from . "\r\nSubject: " . $mail_subject . "\r\nMessage: " . $mail_message . "\r\nSent: " . $time . " on " . $date . "\r\n\r\n\r\nRegards,\r\nThe Mobile Learning Team";
      $mail_headers = 'To: ' . $mail_name . " <" . $mail_from . ">\r\n" .      
                              'From: ' . $mail_name . " <" . $mail_from . ">\r\n" .
                                 'Reply-To: ' . $mail_name . " <" . $mail_from . ">\r\n";
      if ((mail($mail_from, $mail_subject, $full_message, $mail_headers)) == 1) {
            return true;
      }
      else { return false; }
}
?>
<h1>Contact Us</h1>
<p>Sending...<br></p>

<?php
if ((check_name($name, "value") == 1) && (check_email_address($email, "value") == 1) && (check_subject($subject, "value") == 1) && (check_message($message, "value") == 1)) {
      if ((send_original_mail($sendto, $name, $email, $subject, $message) == 1) && (send_confirm_mail($name, $email, $subject, $message) == 1)) {
            echo "<p><b>Result:</b> Your message has been sucessfully sent. A copy of the message has also been sent to your email address.\n</p><br>\n";
      }
} else {
      echo "<p><b>Result:</b> Your form contained one or more errors. Please return to the form and fix them.\n</p><br>\n";
}
?>



Also, perhaps unrelated, it takes 1 second for 1 email to arrive, and up to several hours for the second to arrive (even though theyre both going to the same address while im testing...)

?????????

Thanks!
ASKER CERTIFIED SOLUTION
sakuya_su

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros