actionscripts 3 및 php를 사용하여 전자 메일 보내기에 대한 자습서를 찾았습니다. 프로젝트 파일을 다운로드하고 mail.php를 VPS 서버 xamp htdocs 폴더로 복사했습니다. 애니메이션 CC 프로젝트가 실행되었지만 아무 것도 보내지 않았습니다.액션 스크립트 3 ~ PHP 이메일 보내기
AS3 :
submit_btn.addEventListener(MouseEvent.CLICK, sendMessage);
function sendMessage(e:MouseEvent):void
{
var my_vars:URLVariables = new URLVariables();
my_vars.senderName = name_txt.text;
my_vars.senderEmail = email_txt.text;
my_vars.senderMsg = message_txt.text;
var my_url:URLRequest = new URLRequest("http://my-domain.com/mail.php");
my_url.method = URLRequestMethod.POST;
my_url.data = my_vars;
var my_loader:URLLoader = new URLLoader();
my_loader.dataFormat = URLLoaderDataFormat.VARIABLES;
my_loader.load(my_url);
name_txt.text = "";
email_txt.text = "";
message_txt.text = "Message Sent";
}
PHP :
<?php
$to = "[email protected]"; //Changed to my gmail
$subject = ($_POST['senderName']);
$message = ($_POST['senderMsg']);
$message .= "\n\n---------------------------\n";
$message .= "E-mail Sent From: " . $_POST['senderName'] . " <" . $_POST['senderEmail'] . ">\n";
$headers = "From: " . $_POST['senderName'] . " <" . $_POST['senderEmail'] . ">\n";
if(@mail($to, $subject, $message, $headers))
{
echo "EMAIL SENT";
}
else
{
echo "EMAIL NOT SENT";
}
?>
애니메이션 CC 출력 :
Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs. at Error$/throwError() at flash.net::URLVariables/decode() at flash.net::URLVariables() at flash.net::URLLoader/onComplete()
PHP 출력 :
Notice: Undefined index: senderName in /opt/lampp/htdocs/mail.php on line 3 Notice: Undefined index: senderMsg in /opt/lampp/htdocs/mail.php on line 4 Notice: Undefined index: senderName in /opt/lampp/htdocs/mail.php on line 6 Notice: Undefined index: senderEmail in /opt/lampp/htdocs/mail.php on line 6 Notice: Undefined index: senderName in /opt/lampp/htdocs/mail.php on line 7 Notice: Undefined index: senderEmail in /opt/lampp/htdocs/mail.php on line 7
EMAIL NOT SENT
나는 actionscript와는 아무런 경험이 없지만 최소한 하나의 문제가 게시물 퀘스트 키가 일치하지 않는 것 같습니다. 당신은'senderName'이라는 프라퍼티를 설정했지만 PHP에서는'name'을 읽으려고합니다. 아마 당신의 AS 속성 이름과 일치하도록 PHP post 키를 변경하는 것은 시작일 것입니다 :'$ _POST [ 'senderName']','$ _POST [ 'senderEmail']','$ _POST [ 'senderMsg']' – Steve
코드를 변경했습니다. 그러나 아무것도 바뀌지 않았다. –
AS3 오류를 방지하려면 URLLoaderDataFormat.VARIABLES 행을 주석 처리하십시오. 이 행은 ** 응답 **은 요청이 아니라 key1 = value1 및 key2 = value2 형식의 문자열임을 나타냅니다. PHP의 경우, 들어오는 데이터가 무엇인지 알기 위해 print_r ($ _ POST) 및 print_r ($ _ GET)부터 시작합니다. – Organis