Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
479 views
in Technique[技术] by (71.8m points)

email - PHP mail function 'from' address

I'm not even sure this is possible, however what I'm trying to do is as follows. I have an HTML form that generates and email using a PHP script. What I want is to recieve emails from this form to [email protected], then I want the from address to appear as one of the fields in the form.

I have had a look around and found some useful information on this site. I'm not sure whether sendmail_from can be used in this situation, or if it does what I'm asking.

Is this possible, if so how?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

See this page on the same site (example 2): http://www.w3schools.com/php/func_mail_mail.asp

You will have to set the headers of the message to include the From and other stuff like CC or BCC:

<?php
$to = "[email protected]";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: [email protected]
";

mail($to,$subject,$txt,$headers);
?>

Note that you have to separate the headers with a newline sequence " ".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...