我想从HTML表格发送电子邮件,该电子邮件在发送电子邮件时显示弹出窗口

发布于 2025-01-29 15:18:26 字数 812 浏览 0 评论 0原文

我应该将这篇文章的序言序列,因为我只是一个业余爱好者,而在PHP和JQuery等方面也不是真正的代码。我要做的是使用我在Internet上找到的PHP脚本从HTML表单发送电子邮件。我的工作正常,但是我不喜欢发送电子邮件后,将用户发送到新页面,并带有一条消息,说它已发送。我希望用户不要打开新页面,而是希望用户停留在同一页面上并获得弹出消息。这是我用于PHP脚本的代码:

<?php
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
$name = $_POST['name'] ; 
$email = $_POST['email'] ;
$subject = "Mail from website";
$message = $_POST['message'] ;
$to = "[email protected]";
$headers = "From:" . $email . "\r\n" .
           "Reply-To:" . $email;
if(mail($to,$subject,$message, $headers)) {
    echo "Your email was sucessfully sent!";
} else {
    echo "The email message was not sent.";
}
?>

我没有附上HTML,因为我不认为它确实需要。对此的任何帮助将不胜感激!

I should preface this post with the fact that I am just a hobbyist and am not real code savvy when it comes to PHP and JQuery and such. What I am trying to do is send an email from an HTML form using a PHP script that I found on the internet somewhere. I have this all working just fine, but I dont like the fact that after the email is sent, the user is sent to a new page with a message saying it was sent. Instead of opening a new page, I would like the user to stay on the same page and get a popup message instead. Here is the code I am using for my PHP script:

<?php
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
$name = $_POST['name'] ; 
$email = $_POST['email'] ;
$subject = "Mail from website";
$message = $_POST['message'] ;
$to = "[email protected]";
$headers = "From:" . $email . "\r\n" .
           "Reply-To:" . $email;
if(mail($to,$subject,$message, $headers)) {
    echo "Your email was sucessfully sent!";
} else {
    echo "The email message was not sent.";
}
?>

I did not attach my html since I didnt think it was really needed. Any help on this would be greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请别遗忘我 2025-02-05 15:18:26

重定向到查询字符串,例如header(“位置:formfile?msg = success”);
然后为了拉消息,只需使用$ parts = parse_url($ url); parse_str($ parts ['query'],$ query); $ alert_value = $ _get ['msg'];在您的表单所在的文件中。之后,您可以使用语句进行操作。

这是示例:

表单所在的文件

<?php 
$parts = parse_url($url);
parse_str($parts['query'], $query);
$alert_value = $_GET['msg'];

if ($alert_value == "success") {
//do your actions to show lighbox.
}


?>


<!-- Your code for form in html --->

和您发送电子邮件的文件:

<?php
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
$name = $_POST['name'] ; 
$email = $_POST['email'] ;
$subject = "Mail from website";
$message = $_POST['message'] ;
$to = "[email protected]";
$headers = "From:" . $email . "\r\n" .
           "Reply-To:" . $email;
if(mail($to,$subject,$message, $headers)) {
    header("location: formfile.php?msg=success");
} else {
    header("location: formfile.php?msg=error");
}
?>

Redirect to a query string like header("location: formfile?msg=success");
And then in order to pull message just use $parts = parse_url($url); parse_str($parts['query'], $query); $alert_value = $_GET['msg']; in file where your form is located. After that you can do actions with if statements.

Here is example:

the file where form is located

<?php 
$parts = parse_url($url);
parse_str($parts['query'], $query);
$alert_value = $_GET['msg'];

if ($alert_value == "success") {
//do your actions to show lighbox.
}


?>


<!-- Your code for form in html --->

And your file where you send email:

<?php
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
$name = $_POST['name'] ; 
$email = $_POST['email'] ;
$subject = "Mail from website";
$message = $_POST['message'] ;
$to = "[email protected]";
$headers = "From:" . $email . "\r\n" .
           "Reply-To:" . $email;
if(mail($to,$subject,$message, $headers)) {
    header("location: formfile.php?msg=success");
} else {
    header("location: formfile.php?msg=error");
}
?>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文