我有一个带有php电子邮件脚本的html表单..但是当尝试发送电子邮件时显示错误.. 收件人是空白的!
<?php
$message= " " ;
if (empty ( $mailtoname) || empty ( $mailtomail) ) {
die ( "Recipient is blank! ") ;
}else{
$to = $mailtoname . " <" . $mailtomail . ">" ;
}
if ( empty ( $mailsubject) ) {
$mailsubject=" ";
}
if (($mailpriority>0) && ($mailpriority<6)) {
$mailheader = "X-Priority: ". $mailpriority ."\n";
}
$mailheader.= "From: " . "Sales Team <sales@yourdomain.com>\n";
$mailheader.= "X-Sender: " . "support@yourdomain.com\n";
$mailheader.= "Return-Path: " . "support@yourdomain.com\n";
if (!empty($mailcc)) {
$mailheader.= "Cc: " . $mailcc ."\n";
}
if (!empty($mailbcc)) {
$mailheader.= "Bcc: " . $mailbcc ."\n";
}
if (empty($mailbody)) {
$mailbody=" ";
}
$result = mail ($to, $mailsubject, $mailbody, $mailheader);
echo "<center><b>Mail sent to ". "$to". "<br>";
echo $mailsubject. "<br>";
echo $mailbody. "<br>";
echo $mailheader. "<br>";
if ($result) {
echo "<p><b>Email sent successfully!</b></p>";
}else{
echo "<p><b>Email could not be sent. </b></p>";
}
?>
答案 0 :(得分:1)
快速浏览代码,您不会在处理表单数据的PHP页面中正确调用$_POST
数据。
示例,在您使用的PHP页面中$mailheader.= "Cc: " . $mailcc ."\n";
您需要调用通过POST发送的数据:$mailheader.= "Cc: " . $_POST['mailcc'] ."\n";
我看到其他可能会或可能不会导致错误的事情......修复PHP处理页面中的所有内容,如果它仍然无效,那么我可以更进一步。
答案 1 :(得分:0)
<?php
$message= " " ;
if (empty ( $_POST['mailtoname']) || empty ( $_POST['mailtomail']) ) {
die ( "Recipient is blank! ") ;
}else{
$to = $_POST['mailtoname'] . " <" . $_POST['mailtomail'] . ">" ;
}
if ( empty ( $_POST['mailsubject']) ) {
$mailsubject=" ";
}
else {
$mailsubject = $_POST['mailsubject'];
}
if (($_POST['mailpriority']>0) && ($_POST['mailpriority']<6)) {
$mailheader = "X-Priority: ". $_POST['mailpriority'] ."\n";
}
$mailheader.= "From: " . "Sales Team <sales@yourdomain.com>\n";
$mailheader.= "X-Sender: " . "support@yourdomain.com\n";
$mailheader.= "Return-Path: " . "support@yourdomain.com\n";
if (!empty($_POST['mailcc'])) {
$mailheader.= "Cc: " . $_POST['mailcc'] ."\n";
}
if (!empty($_POST['mailbcc'])) {
$mailheader.= "Bcc: " . $_POST['mailbcc'] ."\n";
}
if (empty($_POST['mailbody'])) {
$mailbody=" ";
}
else {
$mailbody = $_POST['mailbody'];
}
$result = mail ($to, $mailsubject, $mailbody, $mailheader);
echo "<center><b>Mail sent to ". "$to". "<br>";
echo $mailsubject. "<br>";
echo $mailbody. "<br>";
echo $mailheader. "<br>";
if ($result) {
echo "<p><b>Email sent successfully!</b></p>";
}else{
echo "<p><b>Email could not be sent. </b></p>";
}
?>
不知道这是否有效,因为编辑已经删除了HTML表单的链接,但是给它一个运行(只是用$_POST['variable']
替换所有表单变量。即使这个工作,你应该阅读消毒你的表格输入。