dongluyi5123 2014-11-25 12:31
浏览 18
已采纳

PHP电子邮件反馈表

<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];

$mail_to = 'someemail@eample.com';
$subject = 'Feedback from '. $field_name

$body_message = 'From: '.$field_name."
";
$body_message .= 'E-mail: '.$field_email."
";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."
";
$headers .= 'Reply-To: '.$field_email."
";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
    <script language="javascript" type="text/javascript">
        alert('Thank you for your feedback, have a nice day!');
        window.location = 'some undefined location';
    </script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('Sorry your feedback was not sent, please try again soon!');
        window.location = 'some undefined location';
    </script>
<?php
}

?>

I'm trying to create a form that submits the feedback to my desired email adress, the form seems to be running smoothly when i enter all the details but I am not receiving any emails?

Can anyone see why?

Thanks!

  • 写回答

3条回答 默认 最新

  • dongliu0823 2014-11-25 12:52
    关注

    write headers like this :

    $headers = "From: " . $field_email. "
    ";
    $headers .= "Reply-To: ". $field_email. "
    ";
    $headers .= "MIME-Version: 1.0
    ";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1
    ";
    
    example :
    
    $from = "xyz@zz.com";
    $to = "youremail@address.com";
    $subject = "subject trail mail";
    $mail_msg = "trail mail body";
    
    $headers = "From: "  . $from . "
    ";
    $headers .= "Reply-To: ". $from . "
    ";
    $headers .= "MIME-Version: 1.0
    ";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1
    ";
    $retval = mail ($to,$subject,$mail_msg,$headers);
    
    if( $retval == true )  
    {
        $st = "mail sent successfully";
    }
    else{
        $st = "mail error" ;
    }
    echo "mail Status : " . $st ;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了