我有一个php文件 php1.php ,它创建了会话变量
<?php
session_start();
#pathway var
$path=$_GET['path'];
$education=$_GET['edu'];
$cert=$_GET['cert'];
$server_prefix = 'https://';
$server_address = $_SERVER['SERVER_ADDR'];
$_SESSION['pathid']=$path;
$_SESSION['edid']=$education;
$_SESSION['certid']=$cert;
?>
<a href="#" class="contact" id="pathwayshare">Share this pathway!</a>
当用户点击上面的链接时,会显示模态窗口。
用户填写一些表单输入,然后由 php2.php 处理:
session_start();
if ($action == "send") {
//added
#pathway var
var_dump($_SESSION);
$pathval = $_SESSION['pathid'];
$edval = $_SESSION['edid'];
$certval = $_SESSION['certid'];
var_dump($pathval);
var_dump($edval);
var_dump($certval);
$data = array(
"path"=>$pathval,
"edu"=>$edval,
"cert"=>$certval
);
var_dump($data);
$server_prefix = 'https://';
$server_address = $_SERVER['SERVER_ADDR'];
#$fullurl = $server_prefix.$server_address."/career/pathway?ed=".$edval;
// Send the email
$name = isset($_POST["name"]) ? $_POST["name"] : "";
$email = isset($_POST["email"]) ? $_POST["email"] : "";
$subject = isset($_POST["subject"]) ? $_POST["subject"] : $subject;
$message = 'message: '.$server_prefix.$server_address.'/career/pathway?'.http_build_query($data);
var_dump($message);
// $message = $pathval;
var_dump($message);
$cc = isset($_POST["cc"]) ? $_POST["cc"] : "";
$token = isset($_POST["token"]) ? $_POST["token"] : "";
// make sure the token matches
if ($token === smcf_token($to)) {
smcf_send($name, $email, $subject, $message, $cc);
echo "Your message was successfully sent.";
// echo $name . "\n";
// echo $email . "\n";
// echo $subject . "\n";
}
else {
echo "Unfortunately, your message could not be verified.";
}
}
function smcf_send($name, $email, $subject, $message, $cc) {
global $to, $extra;
// Filter and validate fields
$name = smcf_filter($name);
$subject = smcf_filter($subject);
$email = smcf_filter($email);
if (!smcf_validate_email($email)) {
$subject .= " - invalid email";
$message .= "\n\nBad email: $email";
$email = $to;
$cc = 0; // do not CC "sender"
}
// Add additional info to the message
if ($extra["ip"]) {
$message .= "\n\nIP: " . $_SERVER["REMOTE_ADDR"];
}
if ($extra["user_agent"]) {
$message .= "\n\nUSER AGENT: " . $_SERVER["HTTP_USER_AGENT"];
}
// Set and wordwrap message body
$body = "From: Sender\n\n";
$body .= "Message: $message";
$body = wordwrap($body, 70);
// Build header
$headers = "From: $email\n";
if ($cc == 1) {
$headers .= "Cc: $email\n";
}
$headers .= "X-Mailer: PHP/SimpleModalContactForm";
// UTF-8
if (function_exists('mb_encode_mimeheader')) {
$subject = mb_encode_mimeheader($subject, "UTF-8", "B", "\n");
}
else {
// you need to enable mb_encode_mimeheader or risk
// getting emails that are not UTF-8 encoded
}
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain; charset=utf-8\n";
$headers .= "Content-Transfer-Encoding: quoted-printable\n";
// Send email
@mail($to, $subject, $body, $headers) or
die("Unfortunately, a server issue prevented delivery of your message.");
}
此 php2.php 设置电子邮件并发送。问题是,我的var_dump($message)
语句正在输出正确的值,如:
array(3) { ["pathid"]=> string(1) "3" ["edid"]=> string(1) "4" ["certid"]=> string(0) "" } string(1) "3" string(1) "4" string(0) "" array(3) { ["path"]=> string(1) "3" ["edu"]=> string(1) "4" ["cert"]=> string(0) "" } string(65) "message: https://xx.xx.xx.x.x/career/pathway?path=3&edu=4&cert=" string(65) "message: https://xx.xx.xx.x.x/career/pathway?path=3&edu=4&cert=" Your message was successfully sent.
$message
的最后message: https://xx.xx.xx.x.x/career/pathway?path=3&edu=4&cert=
值是准确的,我想要包含在电子邮件中,问题是,电子邮件中发送的信息是:
消息:https://xx.xx.xx.x.x/career/pathway?path=edu=cert
这是不正确的,因为在网址中没有为path
,edu
,cert
发送任何参数 - 我在这里做错了什么?
谢谢