I’m trying to create a simple message form using navigateToURL() and PHP mail(). But I have a problem with this approach it redirects in the php page. I need it not to redirect the page but still send it to the email.
here’s what I did.
AS3
if (e.type == "click")
{
navigateToURL(new URLRequest("http://somedomain.com/sendme.php?" + "name=" + e.currentTarget.parent.na_txt.text + "&email=" + e.currentTarget.parent.ma_txt.text + "&contact=" + e.currentTarget.parent.co_txt.text + "&message=" + e.currentTarget.parent.me_txt.text + "&sex=" + e.currentTarget.parent.sex), "_self");
}
PHP
<?php
$to = "some@email.com";
$subject = "Subject";
$name = $_GET['name'];
$sex = $_GET['sex'];
$email = $_GET['email'];
$contact = $_GET['contact'];
$message = $_GET['message'];
// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.email."\r\n" .
'X-Mailer: PHP/' . phpversion();
$body = "From: $name \r\nGender: $sex \r\nE-Mail: $email \r\nContact No.: $contact \r\n\r\nMessage:\n$message";
echo "Thank You $name, Your Feedback and Enquiry has been submitted to <a href='mailto:$to'>$to</a>!";
mail($to, $subject, $body, $headers);
?>
I think what you really want is to create a URLLoader object to send your variables though.
This will run without reloading the page or opening a new window, allowing you to maintain the state of your application. The text that you echo from PHP will be available in the load complete handler function for you to display to the user however you choose.