UPDATE:iframe解決方案的工作:如何在不重定向的情況下執行表單操作?
<form action="script.php" **target="aniFrame"** method="post" enctype="multipart/form-data">
<label for="file">Package:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>
<iframe name="aniFrame"></iframe>
我執行PHP腳本來發送電子郵件,但不希望用戶在成功進行重定向。我怎樣才能做到這一點? (我的腳本中有一個彈出框,提示「成功!」)謝謝!
<form action="script.php" method="post" enctype="multipart/form-data">
<label for="file">Package:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>
添加我的PHP代碼:
<?php
/**
* Simple example script using PHPMailer with exceptions enabled
* @package phpmailer
* @version $Id$
*/
require '../class.phpmailer.php';
try {
$mail = new PHPMailer(true); //New instance, with exceptions enabled
$body = "Hello, World!";
$mail->IsSMTP(); // tell the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 12; // set the SMTP server port
$mail->Host = "mail.blah.org"; // SMTP server
$mail->Username = "[email protected]"; // SMTP server username
$mail->Password = "pwd"; // SMTP server password
//$mail->IsSendmail(); // tell the class to use Sendmail
$mail->AddReplyTo("[email protected]","First Last");
$mail->From = "[email protected]";
$mail->FromName = "First Last";
$to = "[email protected]";
$mail->AddAddress($to);
$mail->Subject = "First PHPMailer Message";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap = 80; // set word wrap
$mail->MsgHTML($body);
$mail->IsHTML(true); // send as HTML
$mail->Send();
echo "<script type='text/javascript'>alert('submitted successfully!')</script>";
header("HTTP/1.0 204 No Response"); //added this, works but no popup...
}
catch (phpmailerException $e) {
echo $e->errorMessage();
}
>
AJAX是最好的選擇,然後 – Ashish