1

我正在使用以下脚本从我的网页发送电子邮件,用作“推荐朋友”,可用于向朋友发送电子邮件以推荐该网站。这工作正常。但是有一个问题,收到电子邮件的朋友会注意到收到的电子邮件显示带有名称服务器的服务器默认电子邮件地址。我希望收到的电子邮件显示我使用 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>
4

2 回答 2

1

在你的代码中使用类似的东西。

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

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

于 2013-06-26T05:46:09.477 回答
0

尝试这个:

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

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

        $headers .= "Content-type: text/html; charset=UTF-8\n";
于 2013-06-26T06:54:01.307 回答