如果我单击通知按钮,则会发送消息,但不会将其作为电子邮件发送,并且返回的页面也没有再次显示该表,我已回显该消息并且它已存在,但无法解决很多问题
<?php require_once("include/session.php");?>
<?php require_once("include/dataconnect.php");?>
<?php require_once("include/functions.php");?>
<?php include("include/mheader.php");?>
>
<p>
You can contact us so as to give you relevant numbers to speak to.Thank you.
</p>
<?php
$submit = $_POST['Notify'];
$message = mysql_real_escape_string(htmlentities(strip_tags($_POST['message'])));
//echo "$message";
//die();
if('POST' === $_SERVER['REQUEST_METHOD'])
{
if ($message)
{
//Get Email Address
$emails = mysql_query("SELECT reusers.email FROM reusers INNER JOIN repplac ON reusers.username = repplac.Uname AND reusers.username = '{$_SESSION['username']}'")or die(mysql_error());
//$emails = mysql_query("SELECT reusers.email FROM reusers INNER JOIN repplac ON reusers.username = repplac.Uname AND reusers.username = '".$_SESSION['username']."'")or die(mysql_error());
$results = (mysql_fetch_assoc($emails)) or die(mysql_error());
$email= $results['email'];
//echo "$email";
//die();
if(mysql_num_rows($emails) == 0){
exit("No email addresses found for user '{$_SESSION['username']}'");
}
$email = mysql_result($emails, 0);
}
$body = $message;
$to = $email;
$subject = "copy of your notification";
$headers = "From: donotreply@rapsody.co.uk\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'Bcc:los@yahoo.ca' . "\r\n";
mail($to,$subject,$body,$headers);
}
?>
<p>
<form action='notification.php' method='Post' class='rl'>
<div>
<label for='message' class='fixedwidth'>Message</label>
<textarea name="message" rows ="7" cols="40" id="message"></textarea>
</div>
<div class='buttonarea'>
<p>
<input type='submit' name='notify' value='Notify'>
</p>
</div>
</p>
</form>
<?php include("include/footer.php");?>
答案 0 :(得分:0)
使用if ($message) {}
有点棘手,如果您想知道$message
包含一些文字,您可以尝试使用is_null
或is_set
Alos您可以尝试在表单method
之前action
进行模仿
<form method='POST' action='notification.php' class='rl'>
答案 1 :(得分:0)
我能看到的一个问题是:
if ($message)
{
...
$email = mysql_result($emails, 0);
}
$body = $message;
...
现在您正在尝试发送消息,即使$message
评估为false并且您没有要发送的地址。
您需要将邮件发送部分移至if ($message)
部分。
修改:您还要覆盖$email
变量:
$email= $results['email'];
//echo "$email";
//die();
if(mysql_num_rows($emails) == 0){
exit("No email addresses found for user '{$_SESSION['username']}'");
}
$email = mysql_result($emails, 0); // get rid of this line
如果你的评论的echo语句已经给出了正确的结果,你就可以摆脱另一个重复的作业。
除此之外,它可能是服务器问题,邮件被发送到垃圾邮件等,但这与您的代码无关。