[英]“Need Help In Php script” How to avoid sending emails from default server email address
I am using the below script to send emails from my webpage used as " refer a friend " which can be used to send emails to friends to refer the site. 我正在使用以下脚本从我的网页发送电子邮件,以“推荐朋友”的方式使用,该电子邮件可用于向朋友发送电子邮件以推荐该站点。 This works fine.
这很好。 But one problem, Friend who receives the email will notice that the received from emails shows the server default email address with nameservers.
但是有一个问题,收到电子邮件的朋友会注意到,从电子邮件中收到的邮件显示了带有名称服务器的服务器默认电子邮件地址。 I want the received email to show my new account created with info@example.com
我希望收到的电子邮件显示我通过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>
Use something like this in your code. 在代码中使用类似这样的内容。
$headers .= 'From: info@example.com' . "\r\n";
Ref: http://php.net/manual/en/function.mail.php 参考: http : //php.net/manual/en/function.mail.php
Try this: 尝试这个:
$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.