“在Php脚本中需要帮助”如何避免从默认服务器电子邮件地址发送电子邮件

时间:2013-06-26 05:37:11

标签: php function email

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

2 个答案:

答案 0 :(得分:1)

在您的代码中使用类似的内容。

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

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

答案 1 :(得分:0)

试试这个:

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

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

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