我已设置<form action="sendemail.php">
。以下代码写在sendemail.php
中。
问题是我希望在同一个窗口中弹出状态消息contact.html
。它不应该打开一个新窗口,上面写着:
&#34;感谢您与我们联系。我们会尽快与您联系
它出现在一个新的空白窗口中,显示此消息^^^^
。
header('Content-type: application/json');
$status = ("Thank you for contacting us. As early as possible we will contact you"
);
$name = @trim(stripslashes($_POST['name']));
$email = @trim(stripslashes($_POST['email']));
$product_id = @trim(stripslashes($_POST['product_id']));
$phonenumber = @trim(stripslashes($_POST['phonenumber']));
$quantity = @trim(stripslashes($_POST['quantity']));
$subject = @trim(stripslashes($_POST['subject']));
$message = @trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'xyz@gmail.com';
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Product Id: ' . $product_id . "\n\n" . 'Contact Number: ' . $phonenumber . "\n\n" .'Quantity: ' . $quantity . "\n\n" .'Subject: ' . $subject . "\n\n" . 'Complete Address: ' . $message ."\n\n";
$success = @mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
答案 0 :(得分:0)
我不确定您为什么要jSON
,但如果jSON
不需要:
<?php
$name = @trim(stripslashes($_POST['name']));
$email = @trim(stripslashes($_POST['email']));
$product_id = @trim(stripslashes($_POST['product_id']));
$phonenumber = @trim(stripslashes($_POST['phonenumber']));
$quantity = @trim(stripslashes($_POST['quantity']));
$subject = @trim(stripslashes($_POST['subject']));
$message = @trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'xyz@gmail.com';
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Product Id: ' . $product_id . "\n\n" . 'Contact Number: ' . $phonenumber . "\n\n" .'Quantity: ' . $quantity . "\n\n" .'Subject: ' . $subject . "\n\n" . 'Complete Address: ' . $message ."\n\n";
// If main processes successfully, then continue with message
if(@mail($email_to, $subject, $body, 'From: <'.$email_from.'>')) { ?>
<!-- Just write normally -->
Thank you for contacting us. As early as possible we will contact you.
<?php die; } ?>