这很简单,您只需将 header 与mail()函数一起使用:
例如,您可以使用此功能
<?php
function sendMail($to,$subject,$msg,$from = DEFULT_FROM){
// message
$message = '
<html>
<head>
</head>
<body dir="rtl">
<p align="right">'
. $msg .
'</p>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=windows-1256' . "\n";
// Additional heade rs
$headers .= "From: ".$from . "\n";
//$headers .= 'Bcc: info@xxxx.co.uk' . "\n";
// Mail it
return mail($to, $subject, $message, $headers);
}
///// use
$message = " Hi World !";
$subject= "My subject ";
$from=$username@companyname.com /// change $username with your variable
$to ="steve@companyname.com" ;
/////// call function
$check = sendMail($to,$subject,$message ,$from);
if($check){
echo " Sent :) ";
}
else{
echo " Not Sent :( ";
}
?>