Php确认电子邮件不发送 [英] Php Confirmation email does not send

查看:160
本文介绍了Php确认电子邮件不发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在php中进行用户注册和电子邮件确认页面。这是注册用户的代码,并发送确认电子邮件。一切运行正常,它将用户注册到数据库中,但它根本不会将该电子邮件发送给用户。他的代码。

 <?php 

include('sqlconfig.php');

$ tbl_name = temp_users;

/ *电子邮件确认码* /
$ confirm_code = md5(uniqid(rand()));

$ Email = mysql_real_escape_string($ _ POST ['email']);
$ First_Name = mysql_real_escape_string($ _ POST ['firstname']);
$ Last_Name = mysql_real_escape_string($ _ POST ['lastname']);
$ Password = mysql_real_escape_string($ _ POST ['password']);
$ Confirm_pass = mysql_real_escape_string($ _ POST ['conpassword']);
$ Phone = mysql_real_escape_string($ _ POST ['phone']);

/ *将数据插入到基础中* /
$ sql ='INSERT INTO temp_users(confirm,FirstN,LastN,password,confirmpassword,phone,email)
VALUES $。$_ $。$$$$$$$ '',''。$ Email。')';
$ result = mysql_query($ sql);

/ *如果成功插入数据,继续执行此* /
if($ result){

/ *发送电子邮件到这里* /
$ = $电子邮件;

$ subject =Newgenstudios帐户确认;

/ * From * /
$ header =From:Newgenstudios< noreply@newgenstudios.com&

/ *您的消息* /
$ message =欢迎来到Newgenstudios!感谢您注册\r\\\
;
$ message =这是你的确认链接\r\\\
;
$ message。=点击此链接激活您的帐户\r\\\
;
$ message。=http://www.newgensv01.dyndns.org/confirmation.php?passkey=$confirm_code;
$ message =帐户详细信息:\r\\\
;
$ message =Name:$ First_Name $ Last_Name \r\\\
;
$ message =电子邮件:$ Email \r\\\
;
$ message =密码:$密码\r\\\
;
$ message =电话:$ Phone \r\\\
;
$ message =\r\\\
;
$ message =你没有注册?然后请忽略这个消息。\r\\\
;

/ *发送电子邮件* /
$ sentmail = mail($ to,$ subject,$ message,$ header);
}

/ *如果没有找到* /
else {
echo在我们的数据库中找不到你的电子邮件;
}

/ *电子邮件成功发送* /
如果($ sentmail){
echo您的确认链接已发送到您的电子邮件地址。
}
else {
echo无法将确认链接发送到您的电子邮件地址;
}
?>


解决方案

使用PHP附带的mail()函数发送电子邮件的方法并不好,因为它很容易被标记为垃圾邮件,您需要设置标题,以确保正确发送HTML电子邮件。



所以我建议你看看 PHPMailer SwiftMailer ,它具有HTML支持,支持不同的MIME类型和SMTP身份验证


I am trying to make a user registration and email confirmation page in php. This is the code to register the user, and to send a confirmation email. Everything runs fine, and it registers the user into the database, but it does not send the email to the user at all. Heres the code.

<?php

include('sqlconfig.php');

$tbl_name=temp_users;

/*Email Confirmation Code*/
$confirm_code=md5(uniqid(rand())); 

$Email=mysql_real_escape_string($_POST['email']);
$First_Name=mysql_real_escape_string($_POST['firstname']);
$Last_Name=mysql_real_escape_string($_POST['lastname']);
$Password=mysql_real_escape_string($_POST['password']);
$Confirm_pass=mysql_real_escape_string($_POST['conpassword']);
$Phone=mysql_real_escape_string($_POST['phone']);

/*Insert the data into the base*/
$sql = 'INSERT INTO temp_users(confirm, FirstN, LastN, password, confirmpassword, phone, email)
VALUES("'.$confirm_code.'", "'.$First_Name.'", "'.$Last_Name.'", "'.$Password.'", "'.$Confirm_pass.'", "'.$Phone.'", "'.$Email.'")';
$result=mysql_query($sql);

/*If data succesfully inserted proceed with this*/
if($result){

/*Send Email here*/
$to=$Email;

$subject="Newgenstudios Account Confirmation";

/*From*/
$header="From:Newgenstudios <noreply@newgenstudios.com>";

/* Your message */
$message="Welcome to Newgenstudios! Thank you for registering. \r\n";
$message="Here is your Comfirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
$message.="http://www.newgensv01.dyndns.org/confirmation.php?passkey=$confirm_code";
$message="Account Details: \r\n";
$message="Name: $First_Name $Last_Name \r\n";
$message="Email: $Email \r\n";
$message="Password: $Password \r\n";
$message="Phone: $Phone \r\n";
$message="\r\n";
$message="Did you not register? Then please disregard this message. \r\n";

/* Send Email */
$sentmail = mail($to,$subject,$message,$header);
}

/*If not found*/
else {
echo "Not found your email in our database";
}

/* email succesfully sent */
if($sentmail){
echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send Confirmation link to your e-mail address";
}
?>

解决方案

Using the mail() function that comes with PHP is not a good approach in sending email since it is easily marked as spammed, and you need to set up header to ensure that you are sending HTML emails correctly.

So I would suggest you take a look at PHPMailer or SwiftMailer, which has HTML support, support for different mime types and SMTP authentication

这篇关于Php确认电子邮件不发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆