When i try to send email i get this msg Mail failed
Where is worng ?
code:
<?php
function send_mail($to, $body, $subject, $fromaddress, $fromname){
$eol="\r\n";
$mime_boundary=md5(time());
# Common Headers
$headers .= "From: ".$fromname."<".$fromaddress.">".$eol;
$headers .= "Reply-To: ".$fromname."<".$fromaddress.">".$eol;
$headers .= "Return-Path: ".$fromname."<".$fromaddress.">".$eol; // these two to set reply address
$headers .= "Message-ID: <".time()."-".$fromaddress.">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters
# Boundry for marking the split & Multitype Headers
$headers .= 'MIME-Version: 1.0'.$eol.$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$mime_boundary."\"".$eol.$eol;
# Open the first part of the mail
$msg = "--".$mime_boundary.$eol;
$htmlalt_mime_boundary = $mime_boundary."_htmlalt"; //we must define a different MIME boundary for this section
# Setup for text OR html -
$msg .= "Content-Type: multipart/alternative; boundary=\"".$htmlalt_mime_boundary."\"".$eol.$eol;
# Text Version
$msg .= "--".$htmlalt_mime_boundary.$eol;
$msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$msg .= strip_tags(str_replace("<br>", "\n", substr($body, (strpos($body, "<body>")+6)))).$eol.$eol;
# HTML Version
$msg .= "--".$htmlalt_mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$msg .= $body.$eol.$eol;
//close the html/plain text alternate portion
$msg .= "--".$htmlalt_mime_boundary."--".$eol.$eol;
# Finished
$msg .= "--".$mime_boundary."--".$eol.$eol; // finish with two eol's for better security. see Injection.
# SEND THE EMAIL
ini_set(sendmail_from,$fromaddress); // the INI lines are to force the From Address to be used !
$mail_sent = mail($to, $subject, $msg, $headers);
ini_restore(sendmail_from);
return $mail_sent ? "Mail sent" : "Mail failed";
}
if (isset($_POST['send'])) {
//And i use this to use it
$subject = $_POST['subject'];
$body = $_POST['content'];
$from = "test@domain.com";
$to = $_POST['email'];
$fromname = "Hellooo";
$me=send_mail($to, $body, $subject, $from, $fromname);
print $me;
if ($me=="Mail sent"){
echo "<br><div align='center'>Mail Sent</div>";
} else {
echo "<br><div align='center'><font color='#FF0000'><b>Allert! Email has not been sent!</b></font></div>";
}
}
echo "<div align='center'>Send email</div><br /><br />";
echo "<form name='inputform' method='post' action='".$_SERVER['PHP_SELF']."'>";
echo "<table align='center' cellspacing='1' cellpadding='1'>";
echo "<tr>
<td>Subject:</td>
<td><input type='text' name='subject' value='' class='textbox' style='width:250px;'></td>
</tr>";
echo "<tr>
<td>Email:</td>
<td><input type='text' name='email' value='' class='textbox' style='width:250px;'></td>
</tr>";
echo "<tr>
<td valign='top'>Content:</td>
<td><textarea name='content' cols='40' rows='10' class='textbox'></textarea></td>
</tr>";
echo "<tr>
<td align='center' colspan='2'><br>
<input type='submit' name='send' value='Send Now!'></td>
</tr>
</table>
</form>\n";
?>