2017-08-21 43 views
1

我有一個像下面這樣從clevertech網站獲得的註冊表單,它正在向新用戶發送郵件驗證,並且用戶正在收到郵件,並且每件事情都正常工作,但是:用戶收到郵件與發件人爲:[email protected]在註冊中更改發件人郵件cpanel

我希望它發送郵件從我的E_mail帳戶之一,而不是像[email protected]。我的PHP代碼下面有 。

<?php /* Registration process, inserts user info into the database 
and sends account confirmation email message */ 

// Set session variables to be used on profile.php page 
$_SESSION['email'] = $_POST['email']; 
$_SESSION['first_name'] = $_POST['firstname']; 
$_SESSION['last_name'] = $_POST['lastname']; 

$_SESSION['City'] = $_POST['City']; 
$_SESSION['Postal'] = $_POST['Postal']; 

$_SESSION['Street'] = $_POST['Street']; 
$_SESSION['buildingNo'] = $_POST['buildingNo']; 

$_SESSION['phone'] = $_POST['phone']; 
$_SESSION['noteadress'] = $_POST['noteadress']; 


// Escape all $_POST variables to protect against SQL injections 
$first_name = $mysqli->escape_string($_POST['firstname']); 
$last_name = $mysqli->escape_string($_POST['lastname']); 

$City = $mysqli->escape_string($_POST['City']); 
$Postal = $mysqli->escape_string($_POST['Postal']); 

$Street = $mysqli->escape_string($_POST['Street']); 
$buildingNo = $mysqli->escape_string($_POST['buildingNo']); 

$phone = $mysqli->escape_string($_POST['phone']); 
$noteadress = $mysqli->escape_string($_POST['noteadress']); 

$email = $mysqli->escape_string($_POST['email']); 
$password = $mysqli->escape_string(password_hash($_POST['password'], 
PASSWORD_BCRYPT)); 
$hash = $mysqli->escape_string(md5(rand(0,1000))); 

// Check if user with that email already exists 
$result = $mysqli->query("SELECT * FROM customer WHERE email='$email'") or die($mysqli->error()); 

// We know user email exists if the rows returned are more than 0 
if ($result->num_rows > 0) { 

$_SESSION['message'] = 'User with this email already exists!'; 
header("location: error.php"); 
} 
else { // Email doesn't already exist in a database, proceed... 

// active is 0 by DEFAULT (no need to include it here) 
$sql = "INSERT INTO customer (first_name, last_name, email, password, 
hash,Street,City,buildingNo,Noteadress,Postal,phone) " 
     . "VALUES ('$first_name','$last_name','$email','$password', '$hash', 
'$Street','$City','$buildingNo','$Noteadress','$Postal','$phone')"; 

// Add user to the database 
if ($mysqli->query($sql)){ 

    $_SESSION['active'] = 0; //0 until user activates their account with 
verify.php 
    $_SESSION['logged_in'] = true; // So we know the user has logged in 
    $_SESSION['message'] = 

      "Confirmation link has been sent to $email, please verify 
      your account by clicking on the link in the message!"; 

    // Send registration confirmation link (verify.php) 
    $to  = $email; 
    $subject = 'Account Verification (MereBuy.com)'; 
    $message_body = ' 
    Hello '.$first_name.', 

    Thank you for signing up! 

    Please click this link to activate your account: 

    mywebsite.com/verify.php?email='.$email.'&hash='.$hash; 

    mail($to, $subject, $message_body); 

    header("location: profile.php"); 

} 

else { 
    $_SESSION['message'] = 'Registration failed,Or first Name Exist!'; 
    header("location: error.php"); 
} 

} 

回答

0

您需要additional_header小號頭添加到您的電子郵件,

這通常是用來添加額外的頭(發件人,抄送,和密件抄送)

$header = "MIME-Version: 1.0" . "\r\n"; 
$header .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 
$header .= 'From: YOUR Website Name <[email protected]>' . "\r\n"; 

然後

mail($to, $subject, $message_body,$header); 
+0

謝謝Masivuye Cokile它按預期工作,仍然在它的標題如下:notifications @ yourd omain.com通過p3plcpnl0732.prod.phx3.secureserver.net 但它比以前更好。 – hussam

+0

很酷。高興可以幫助 –