Hostgator共享服务器在提交Pear邮件脚本后挂起

时间:2012-10-28 06:19:30

标签: php html pear

显然我的hostgator共享托管服务器在下面的脚本运行后挂起。

虽然脚本返回成功发送的消息,但不会发送。我在整个网站上使用SMTP设置进行验证。我在这个文档中找不到任何错误,我的主机似乎没有任何线索,无论它为什么挂起或为什么它不发送。

我忽略了什么吗?有什么想法吗?

<?php
require_once "Mail.php";
include('../../Redirect_modules.php');

function sendmail($type,$subject,$body)
{
  if($type==1) $WET = DBGet(DBQuery("SELECT * FROM staff"));
  else $WET = DBGet(DBQuery("SELECT * FROM staff where profile='$type'"));  

  $from = "";

  $host = "";
  $username = "";
  $password = "";

  $headers = array ('From' => $from,
    'To' => $to,
    'Subject' => $subject);

  $smtp = Mail::factory('smtp',
    array ('host' => $host,
      'auth' => true,
      'username' => $username,
      'password' => $password));

  $mail = $smtp->send($to, $headers, $msg);

  foreach($WET as $e)
  {
    $to = $e['EMAIL'];
    $mail = $smtp->send($to, $headers, $body);

    if (PEAR::isError($mail)) {
      echo("<p>" . $mail->getMessage() . "</p>");
    } else {
      //echo("<p>Message successfully sent!!</p>");
    }
  }
}

function sendsinglemail($to,$subject,$body)
{
  $from = "Your Name";

  $host = "";
  $username = "";
  $password = "";

  $headers = array ('From' => $from,
    'To' => $to,
    'Subject' => $subject);

  $smtp = Mail::factory('smtp',
    array ('host' => $host,
      'auth' => true,
      'username' => $username,
      'password' => $password));

  $mail = $smtp->send($to, $headers, $body);

  if (PEAR::isError($mail)) {
    echo("<p>" . $mail->getMessage() . "</p>");
  } 
  else {
    echo("<p>Message successfully sent!!</p>");
  }

}

if($_REQUEST['modfunc']=='send')
{
  if($_POST['roption2']=='0')
  {
    sendmail($_POST['roption1'],$_POST['subject'],$_POST['message']);       
  }
  else
  {
    sendsinglemail($_POST['roption2'],$_POST['subject'],$_POST['message']); 
  }
}

$RET = DBGet(DBQuery("SELECT * FROM staff")); 
?>

<h2> Communicate with Teachers or Parents individually or by group via Email </h2>
<form action="<?php echo "Modules.php?modname=$_REQUEST[modname]&modfunc=send" ?>"     method=POST>
 <table width="500">
 <tr><td> To:</td> <td><select name="roption1" id="groupselect">
 <option value="1">All Administrators, Teachers and Parents</option> 
 <option value="admin">All Administrators</option>
 <option value="teacher">All Teachers </option>
 <option value="parent">All Parents</option>
 </select> 
  or 
 <select  name="roption2" id="individual">
    <option value="0" SELECTED>Select User</option> 
    <?php foreach($RET as $userdata){ ?>
      <option value="<?php echo $userdata['EMAIL']; ?>"><?php echo    $userdata['FIRST_NAME']." ".$userdata['LAST_NAME']; ?></option>
    <?php } ?>
 </select> 
 </td>
 </tr>
 <tr><td> Subject:</td> <td> <input type="text" name="subject" /> </td></tr>
 <tr> <td> </td> <td>Message: <br/> <textarea cols="60" rows="10" name="message">    </textarea> </td></tr>
  <tr> <td><input type="submit" value="send" name="submit" />
 </table>
</form>
<?php
?>

1 个答案:

答案 0 :(得分:0)

我发现错误,FROM字段未正确填充,因此在反弹后导致挂起!