发送确认电子邮件时出错

发布于 2024-12-11 17:08:49 字数 1842 浏览 0 评论 0原文

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

    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);

}

I'm creating a user registration form and after they fill in all the information and submit the form all of the data goes in my database table. After a successful registration A confirmation email is sent to the users email address which is supplied by the user in the registration form. But the email is not sending.I am getting the error message shown below:

    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. 

This is the function I am using in my registration form:

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

and:

 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);

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吹泡泡o 2024-12-18 17:08:49

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

尝试使用

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

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

它应该是这种格式

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

This error is from your smtp setup and not your code. You should verify that your smtp is properly set up.

Try using

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

To get your SMTP details.
Check your php.ini

It should be in this kinda format

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文