发送确认电子邮件时出错
我正在创建一个用户注册表单,在他们填写所有信息并提交表单后,所有数据都会进入我的数据库表中。成功注册后,确认电子邮件将发送至用户在注册表中提供的电子邮件地址。但电子邮件没有发送。我收到如下所示的错误消息:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此错误来自您的 smtp 设置,而不是您的代码。您应该验证您的 smtp 设置是否正确。
尝试使用
获取您的 SMTP 详细信息。
检查你的 php.ini
它应该是这种格式
This error is from your smtp setup and not your code. You should verify that your smtp is properly set up.
Try using
To get your SMTP details.
Check your php.ini
It should be in this kinda format