簡體   English   中英

PHP確認電子郵件未發送

[英]Php Confirmation email does not send

我正在嘗試在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";
}
?>

使用PHP隨附的mail()函數不是發送電子郵件的好方法,因為它很容易被標記為垃圾郵件,並且您需要設置標頭以確保正確發送HTML電子郵件。

因此,我建議您看看PHPMailerSwiftMailer ,它們具有HTML支持,支持不同的mime類型和SMTP身份驗證。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM