Forum Moderators: coopster
The contact form is in flash movie embedded in index.html. The flash file and php file are together in a subdirectory. Would this affect its function?
The server is running apache 2... and php 5...
Any advice would be appreciated.
This is the php script called flashEmailer.php:
----------------------------------------------------------
$recipients = "myemail@example.com";
$subject = "The Message";
// Grab the key from Flash to ensure security
$sendKey = $_POST['key'];
// Only allow the page to send if Flash is the requester
if($sendKey == "email") {
// The following three variables are gathered from Flash
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
// Grab todays date
$date = date("F j, Y", time());
// This block is the actual message that is sent in the email
$email_info .= "Below is the visitors contact info and message.\n\n";
$email_info .= "Visitor's Info:\n";
$email_info .= "-----------------------------------------\n";
$email_info .= "Name: " . $name . "\n";
$email_info .= "Email: " . $email . "\n";
$email_info .= "Date Sent: " . $date . "\n\n";
$email_info .= "Message\n";
$email_info .= "-----------------------------------------\n";
$email_info .= "" . $message . "\n";
$mailheaders = "From: email@example.com <> \n";
$mailheaders .= "Reply-To: " . $email . "\n\n";
if(mail($recipients, $subject, $email_info, $mailheaders)) {
// Print a success for Flash to know the email is being sent
print "&success=true";
}
}
?>
------------------------------------------------------------
This is the actionscript for the contact form.
-------------------------------------------------------------
var contact_php_file = "flashEmailer.php";
send_btn.onRelease = function() {
checkForm();
}
function validateEmail(address) {
// Check address length
if(address.length >= 7) {
// Check for an @ sign
if(address.indexOf("@") > 0) {
// Check for at least 2 characters following the @
if((address.indexOf("@") + 2)<address.lastIndexOf(".")) {
// Check for a domain name of at least 2 characters
if (address.lastIndexOf(".") < (address.length - 2)) {
// If all the above tests pass, the email address is in valid format
return true;
}
}
}
}
// Called if the email fails
trace("The entered email address is invalid.");
return false;
}
function checkForm() {
n = form.name_txt.text;
e = form.email_txt.text;
m = form.msg_txt.text;
if(m != "" && e != "" && validateEmail(e)) {
sendEmail(n, e, m);
} else {
trace("All Required Fields Not Filled In!");
}
}
function sendEmail(n, e, m) {
session = "?nocache=" + random(999999);
contact_lv = new LoadVars();
contact_lv.name = n;
contact_lv.email = e;
contact_lv.message = m;
contact_lv.key = "email";
trace(n + " - " + e + " - " + m);
contact_lv.sendAndLoad(contact_php_file + session, contact_lv, "POST");
contact_lv.onLoad = function(success) {
if(!success) {
return trace("Error calling PHP File!");
} else {
return trace("Email Sent!");
}
}
}
stop();
[edited by: dreamcatcher at 7:00 am (utc) on June 15, 2009]
[edit reason] Removed specifics [/edit]
if(mail($recipients, $subject, $email_info, $mailheaders)) {
// Print a success for Flash to know the email is being sent
print "&success=true";
}
that just means that your message was successfully added to the mail queue, in this case to sendmail's mail queue
you could look at the maillog in sendmail, mine happens to be located at /var/log/maillog that could show you more about what happened to the message.
The odds are you just aren't getting it, check your spam folder first.
Then I would make sure you have an email address you control in the headers
$mailheaders = "From: email@example.com <> \n";
$mailheaders .= "Reply-To: " . $email . "\n\n";
and add a couple that help
$myemail = 'email@example.com';
$mailheaders = "From: $myemail <$myemail>\n";
$mailheaders .= "Return-Path: $myemail\n";
$mailheaders .= "Reply-To: $myemail\n";
try with that chunk and see what happens, if you set the $myemail var to an account you control you may get a bounce message that might help as well.
I have set up apache and php 5 as local host.
How can I check if the mail is being sent by using local host.
Its actually quite embarassing but I found an article that seemed to have the solution, but involved setting up apache and php 5. Anyway it took me ages and when i finally got it working I realised I had cleared the cache and cant find the article again for the life of me!
Pretty silly...
I am also trying to acheive the same thing from localhost as a means of testing but I cant work it out.
did you test the things I mentioned on your server?
you can use sendmail to send mail, you don't need "smtp installed" per se, so leave that for now
don't worry about your local setup as you need to diagnose what is happening on the server.
so step 1
was the mail function successful?
how to test
you currently have this
if(mail($recipients, $subject, $email_info, $mailheaders)) {
// Print a success for Flash to know the email is being sent
print "&success=true";
}
which seems to print "&success=true" when the mail function is successful, not my approach but
does this get output when you submit your form?
I might change the above if to output something for false too
if(mail($recipients, $subject, $email_info, $mailheaders)) {
// Print a success for Flash to know the email is being sent
print "&success=true";
} else {
print "&success=false";
}
When i test it on the server i dont know how to do any form of error checking.
the action for the form is :
var contact_php_file = "flashEmailer.php";
and is called
when all the criteria are met for filling in the form:
contact_lv.sendAndLoad(contact_php_file + session, contact_lv, "POST");
the file flashEmailer.php is in the same location as the flash movie.
-----------------------------------------------------------
In short can you give me advice on how to check the mail function on the server. I don't have access to or don't know how to find the maillog file. Im sure my actionscript is not the problem.
How do i display the result of the error checking that i have put in my flash files when the site is online?