mail()函数不能在php上运行

时间:2012-01-05 15:00:28

标签: php debugging email

mail($to, $subject, $message, $from);功能在以下代码中无效。

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
       <html xmlns="http://www.w3.org/1999/xhtml">
       <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Untitled Document</title>
       </head>
       <body>
        <?php
         if ($_POST['Gender'] = 'M') {
          $prefix = 'Mr.';
         }else if($_POST['Gender'] = 'F') {
          $prefix = 'Miss/ Mrs.';
         }

         $start1 = "The message: " . $_POST['Subject'] . "/n Was sent to you at " . date('l jS \of F Y h:i:s A'); 
         $sender = "By: " .  $prefix . "  " . $_POST['Name'];
         $content = "The message : /n /n" . $_POST['Massage'];
         $sufix = "To reply to this email:  " . $_POST['Email'];
         $from = $_POST['Email'];

         $to = "info@mybataba.com";
         $subject = "You have a new massage on mybataba.com" . $_POST['Subject'];
         $message = $start1 . $sender . $content . $sufix

         mail ($to, $subject, $message, $from);  
        ?>
       </body>
       </html>

3 个答案:

答案 0 :(得分:1)

$message = $start1 . $sender . $content . $sufix

应该是

$message = $start1 . $sender . $content . $sufix; 

这就是你收到错误的原因

  

解析错误:语法错误,意外的T_STRING   第27行/home/R6iJfd/prog.php

答案 1 :(得分:1)

$from应该是标题。所以,你需要写这个:

$from = 'From: '.$_POST['Email'];

您还有其他问题,但与邮件无关:

if ($_POST['Gender'] = 'M') {

应该是:

if ($_POST['Gender'] == 'M') {

答案 2 :(得分:0)

您遇到编程问题(将抛出错误)

您需要在PHP.INI确认您的邮件设置是否正确,这取决于您的服务器软件是否配置为发送邮件,而不是PHP中的发送。

一旦确定您的服务器配置正确,您的PHP mail()就可以正常工作

修改

您也注意到此行中缺少;

$message = $start1 . $sender . $content . $sufix