发送确认电子邮件时出错

时间:2011-10-24 10:05:03

标签: php oop smtp localhost

我正在创建一个用户注册表单,在他们填写所有信息并提交表单后,所有数据都会在我的数据库表中。注册成功后,确认电子邮件将发送到用户在注册表单中提供的用户电子邮件地址。但是电子邮件没有发送。我收到如下所示的错误消息:

    Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port        
     25,  verify your "SMTP" and "smtp_port" setting in 
  php.ini or use ini_set() in D:\wamp\www\boobloom\site\class.Utility.inc.php on line 25
   Registration Successful. 

这是我在注册表中使用的功能:

if(mysql_query($insert_query)){
    Utility::sendRegConfirmEmail(mysql_insert_id());
    echo $message = "Registration Successful.";
}else{
    echo $message = "Registration not Successful.";
}

 static function sendRegConfirmEmail($id){
    $query = "SELECT * FROM users WHERE id = '".$id."'";
    $result = mysql_query($query) or die(mysql_error());
    $row  = mysql_fetch_assoc($result);
    $to = $row['email'];
            $confirmationcode = $row['confirmation_code'];
    $tVar = time();
    $confirmLink = HTTP_PATH.'registrationConfirm/'.md5($tVar).'/'.$to.'/'.$confirmationcode.'/'.md5($to);
    // to fetch the email template
    $queryET = "SELECT * FROM emailtemplates WHERE type = 'registration_confirmation'";
    $resultET = mysql_query($queryET) or die(mysql_error());
    $rowET  = mysql_fetch_assoc($resultET);
    $subject = $rowET['subject'];
    $toRepArray   = array('[!Name!]','[!email!]','[!PASSWORD!]','[!activation_code!]','[!Link!]');
    $fromRepArray = array($to,$to,$row['password'],$confirmationcode,$confirmLink);
    $message = str_replace($toRepArray,$fromRepArray,$rowET['message']);
    $headers  = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers .= "From: boobloom.com <".SITE_MAIL.">\r\n";
            mail($to, $subject, $message, $headers);

}

1 个答案:

答案 0 :(得分:0)

此错误来自您的smtp设置,而不是您的代码。您应该验证您的smtp是否已正确设置。

尝试使用

echo ini_get("SMTP");
echo ini_get("smtp_port");

获取SMTP详细信息。 检查你的php.ini

它应该采用这种格式

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25
相关问题