簡體   English   中英

“需要PHP腳本幫助”如何避免從默認服務器電子郵件地址發送電子郵件

[英]“Need Help In Php script” How to avoid sending emails from default server email address

我正在使用以下腳本從我的網頁發送電子郵件,以“推薦朋友”的方式使用,該電子郵件可用於向朋友發送電子郵件以推薦該站點。 這很好。 但是有一個問題,收到電子郵件的朋友會注意到,從電子郵件中收到的郵件顯示了帶有名稱服務器的服務器默認電子郵件地址。 我希望收到的電子郵件顯示我通過info@example.com創建的新帳戶

(This is the php script)

$status = "OK"; 
$msg=""; 

if (isset($_POST['submit'])) {

$y_email=$_POST['y_email']; 
$y_name=$_POST['y_name']; 

$f_email=$_POST['f_email']; 
$f_name=$_POST['f_name']; 
$y_msg=$_POST['y_msg']; 
if(substr_count($y_email,"@") > 1 or substr_count($f_email,"@") > 1){ 
$msg .="Use only one email address<br />"; 
$status= "NOTOK"; 
} 
if (!stristr($y_email,"@") OR !stristr($y_email,".")) { // checking your email 
$msg .="Your email address is not correct<br />"; 
$status= "NOTOK";} 
if (strlen($y_name) <2 ) { // checking your name 
$msg .="Please enter your name<br />"; 
$status= "NOTOK";} 
if (!stristr($f_email,"@") OR !stristr($f_email,".")) { // checking friends email 
$msg .="Your Friends address is not correct<br />"; 
$status= "NOTOK";} 
if (strlen($f_name) <2 ) { // checking freinds name 
$msg .="Please enter your friend's name<br />"; 
$status= "NOTOK";} 

if($status=="OK"){ // all validation passed 

/////////// Sending the message starts here ////////////// 
$ref=@$HTTP_REFERER; 
/////Message at the top of the page showing the url//// 
$header_message = ""; 
/// Body message prepared with the message entered by the user //// 
$body_message =$header_message." ".$y_msg." "; 
$body_message .="Hi $f_name wants you to know about this great service!"; 
//// Mail posting part starts here ///////// 
$headers=""; 
//$headers = "Content-Type: text/html; charset=iso-8859-1n".$headers; 
// Un comment the above line to send mail in html format 
$headers4=$y_email; // Change this to change from address 
$headers.="Reply-to: $headers4n"; 
$headers .= "From: $headers4n"; 
$headers .= "Errors-to: $headers4n"; 
$subject="Hello!"; 
mail($f_email,$subject,$body_message,$headers); 
////// Mail posting ends here /////////// 

}
}




(form)

 <form action="" method="post" id="refer-friend"> 
<strong style="font-size:12px">Your Full Name</strong> 
<br />
<input name="y_name" value="<?php if (isset($_POST['y_name'])) ?>" type="text" />
<br />
<strong style="font-size:12px">Your Email</strong>
<br />
<input name="y_email" value="<?php if (isset($_POST['y_email']))?>" type="text" /> 

<br />
<br />
<br />

<strong style="font-size:12px">Your Friends Name</strong>
<br />
<input name="f_name" value="<?php if (isset($_POST['f_name']))?>" type="text" />
<br />
<strong style="font-size:12px">your Friends Email</strong>
<br />
<input name="f_email" value="<?php if (isset($_POST['f_email']))?>" type="text" />
<br />
    <br />

<p>
                    <button type="submit" name="submit" class="button orange">Send Request</button>
                </p> 
</form>

在代碼中使用類似這樣的內容。

 $headers .= 'From: info@example.com' . "\r\n";

參考: http : //php.net/manual/en/function.mail.php

嘗試這個:

            $headers = "From: <$y_email>\n";

        $headers .= "MIME-Version: 1.0\n"; 

        $headers .= "Content-type: text/html; charset=UTF-8\n";

暫無
暫無

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

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