brad_tho
asked on
mail() function having strange results
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\nT he 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($emai l, "value") == 1) && (check_subject($subject, "value") == 1) && (check_message($message, "value") == 1)) {
if ((send_original_mail($send to, $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!
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\nT
$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($emai
if ((send_original_mail($send
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!
Can you post the rest of the functions and the headers from the emails that it sends? Also, you should be careful about using statements like 'return true' and then using '1' as a test for it. While most times this will work out, it won't necessarily always. If you use the word reference in one part, use it in all parts. Or use the number in all parts. Have you tried using another email address? The fact that you're setting the to and from headers to the same thing could be related. There could be filters causing the delay. Or you could simply be confusing the mail server or there could be filters involved...that could trip a lot of things in a lot of ways. And if nothing else, most spam filters will flag it if it is from/to the same person. Looking at just what's there, though, I can't see what would be causing it to send 2 messages. I'm guessing there's either something in the rest of the code causing it, there's another detail that hasn't been mentioned yet, or it may possibly just be the mail server.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.
I will leave the following recommendation for this question in the Cleanup topic area:
Accept: sakuya_su {http:#18110438}
Any objections should be posted here in the next 4 days. After that time, the question will be closed.
Huji
EE Cleanup Volunteer
I will leave the following recommendation for this question in the Cleanup topic area:
Accept: sakuya_su {http:#18110438}
Any objections should be posted here in the next 4 days. After that time, the question will be closed.
Huji
EE Cleanup Volunteer