Trubble使用php发送带有cc和bcc的emil


Trubble sending emil with cc and bcc using php

我有一个带有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>";
}
?>

快速浏览一下您的代码,您没有在处理表单数据的 PHP 页面中正确调用$_POST数据。

例如,在PHP页面中,$mailheader.= "Cc: " . $mailcc ."'n";您需要调用通过POST发送的数据:$mailheader.= "Cc: " . $_POST['mailcc'] ."'n";

我看到其他可能会导致错误或可能不会导致错误的事情......修复 PHP 处理页面中的所有问题,如果它仍然不起作用,那么我可以更进一步。

<?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'] . 即使这有效,您也应该阅读清理表单输入的信息。