1

我正在尝试在 php 中创建用户注册和电子邮件确认页面。这是注册用户和发送确认电子邮件的代码。一切运行良好,它将用户注册到数据库中,但它根本不向用户发送电子邮件。这是代码。

<?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";
}
?>
4

1 回答 1

0

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

所以我建议你看看PHPMailerSwiftMailer,它们支持 HTML,支持不同的 mime 类型和 SMTP 身份验证

于 2012-12-01T04:31:51.200 回答