我想从HTML表格发送电子邮件,该电子邮件在发送电子邮件时显示弹出窗口
我应该将这篇文章的序言序列,因为我只是一个业余爱好者,而在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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
重定向到查询字符串,例如
header(“位置:formfile?msg = success”);
然后为了拉消息,只需使用
$ parts = parse_url($ url); parse_str($ parts ['query'],$ query); $ alert_value = $ _get ['msg'];
在您的表单所在的文件中。之后,您可以使用语句进行操作。这是示例:
表单所在的文件
和您发送电子邮件的文件:
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
And your file where you send email: