miworld
New Member
- Messages
- 16
- Reaction score
- 0
- Points
- 0
Hello, In this script, the send() function is not working. It is showing that mail has been sent. But originally mail did not send. This problem only happens for send() function, I mean for sending mail with attachment. Please help me.
This is the script :
<html>
<head>
<title>
Send Mail
</title>
</head>
<body>
<center>
<?php
if(($_POST['replyto']=="@") || ($_POST['replyto']==""))
{
$replyto=$_POST['from'];
}
else
{
$replyto=$_POST['replyto'];
}
$copy=$_POST['copy'];
$copytosender=$_POST['copytosender'];
function mailAttachment($to, $subject, $message, $name, $from, $replyto, $file)
{
$udata = explode("/",$file);
$udata = array_reverse($udata);
copy("$file", "upload/$udata[0]");
$file_name = $udata[0];
$boundary = strtoupper(md5(uniqid(time())));
$mail_header = "From: $name <$from>\n";
$mail_header .= "Reply-To: $replyto\n";
$mail_header .= "MIME-Version: 1.0";
$mail_header .= "\nContent-Type: multipart/mixed; boundary=$boundary";
$mail_header .= "\n--$boundary";
$mail_header .= "\n\n$message";
$file_content = fread(fopen("upload/$udata[0]","r"),filesize("upload/$udata[0]"));
$file_content = chunk_split(base64_encode($file_content));
$mail_header .= "\n--$boundary";
$mail_header .= "\nContent-Type: application/octetstream; name=\"$file_name\"";
$mail_header .= "\nContent-Transfer-Encoding: base64";
$mail_header .= "\nContent-Disposition: attachment; filename=\"$file_name\"";
$mail_header .= "\n\n$file_content";
$mail_header .= "\n--$boundary--";
if(mail($to, $subject, "", $mail_header)) unlink("upload/$udata[0]");
}
function send($to, $subject, $message, $name, $from, $replyto, $file, $copy, $copytosender)
{
if(eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$",$to))
{
for($i=0;$i<$copy;$i++)
{
mailAttachment($to, $subject, $message, $name, $from, $replyto, $file);
}
echo "Your Mail Has Been Successfully Sent To $to With Attachment";
if($copytosender=="y")
{
if(eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$",$from))
{
mailAttachment($from, $subject, $message, $name, $from, $replyto, $file);
echo "<br>A Copy Of Your Mail Has Been Successfully Sent To $from With Attachment";
}
else
{
echo "<br>Unable To Send A Copy Of Your Mail To Sender";
}
}
}
else
{
echo "Unable To Send Mail";
}
}
if(($_POST['file']=="") || ($_POST['file']=="http://"))
{
$to = $_POST['to'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$from = $_POST['from'];
$mail_header = "From: ".$_POST["name"]. "<".$_POST["from"].">\r\n";
$mail_header .= "Reply-To: $replyto\r\n";
if(eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$",$to))
{
for($i=0;$i<$copy;$i++)
{
mail($to, $subject, $message, $mail_header);
}
echo "Your Mail Has Been Successfully Sent To $to";
if($copytosender=="y")
{
if(eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$",$from))
{
mail($from, $subject, $message, $mail_header);
echo "<br>A Copy Of Your Mail Has Been Successfully Sent To $from";
}
else
{
echo "<br>Unable To Send A Copy Of Your Mail To Sender";
}
}
}
else
{
echo "Unable To Send Mail";
}
}
else
{
$to = $_POST['to'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$name = $_POST['name'];
$from = $_POST['from'];
$file = $_POST['file'];
send($to, $subject, $message, $name, $from, $replyto, $file, $copy, $copytosender);
}
?>
<br><br><a href="index.php">BACK</a>
</center>
</body>
</html>
This is the script :
<html>
<head>
<title>
Send Mail
</title>
</head>
<body>
<center>
<?php
if(($_POST['replyto']=="@") || ($_POST['replyto']==""))
{
$replyto=$_POST['from'];
}
else
{
$replyto=$_POST['replyto'];
}
$copy=$_POST['copy'];
$copytosender=$_POST['copytosender'];
function mailAttachment($to, $subject, $message, $name, $from, $replyto, $file)
{
$udata = explode("/",$file);
$udata = array_reverse($udata);
copy("$file", "upload/$udata[0]");
$file_name = $udata[0];
$boundary = strtoupper(md5(uniqid(time())));
$mail_header = "From: $name <$from>\n";
$mail_header .= "Reply-To: $replyto\n";
$mail_header .= "MIME-Version: 1.0";
$mail_header .= "\nContent-Type: multipart/mixed; boundary=$boundary";
$mail_header .= "\n--$boundary";
$mail_header .= "\n\n$message";
$file_content = fread(fopen("upload/$udata[0]","r"),filesize("upload/$udata[0]"));
$file_content = chunk_split(base64_encode($file_content));
$mail_header .= "\n--$boundary";
$mail_header .= "\nContent-Type: application/octetstream; name=\"$file_name\"";
$mail_header .= "\nContent-Transfer-Encoding: base64";
$mail_header .= "\nContent-Disposition: attachment; filename=\"$file_name\"";
$mail_header .= "\n\n$file_content";
$mail_header .= "\n--$boundary--";
if(mail($to, $subject, "", $mail_header)) unlink("upload/$udata[0]");
}
function send($to, $subject, $message, $name, $from, $replyto, $file, $copy, $copytosender)
{
if(eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$",$to))
{
for($i=0;$i<$copy;$i++)
{
mailAttachment($to, $subject, $message, $name, $from, $replyto, $file);
}
echo "Your Mail Has Been Successfully Sent To $to With Attachment";
if($copytosender=="y")
{
if(eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$",$from))
{
mailAttachment($from, $subject, $message, $name, $from, $replyto, $file);
echo "<br>A Copy Of Your Mail Has Been Successfully Sent To $from With Attachment";
}
else
{
echo "<br>Unable To Send A Copy Of Your Mail To Sender";
}
}
}
else
{
echo "Unable To Send Mail";
}
}
if(($_POST['file']=="") || ($_POST['file']=="http://"))
{
$to = $_POST['to'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$from = $_POST['from'];
$mail_header = "From: ".$_POST["name"]. "<".$_POST["from"].">\r\n";
$mail_header .= "Reply-To: $replyto\r\n";
if(eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$",$to))
{
for($i=0;$i<$copy;$i++)
{
mail($to, $subject, $message, $mail_header);
}
echo "Your Mail Has Been Successfully Sent To $to";
if($copytosender=="y")
{
if(eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$",$from))
{
mail($from, $subject, $message, $mail_header);
echo "<br>A Copy Of Your Mail Has Been Successfully Sent To $from";
}
else
{
echo "<br>Unable To Send A Copy Of Your Mail To Sender";
}
}
}
else
{
echo "Unable To Send Mail";
}
}
else
{
$to = $_POST['to'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$name = $_POST['name'];
$from = $_POST['from'];
$file = $_POST['file'];
send($to, $subject, $message, $name, $from, $replyto, $file, $copy, $copytosender);
}
?>
<br><br><a href="index.php">BACK</a>
</center>
</body>
</html>