查看: 1078|回复: 7
|
PHP Email
[复制链接]
|
|
simpleemail.htm
<html>
<head>
<title>New Page 1</title>
</head>
<body>
<form method="POST" action="mail.php">
<p>To:<br /><input type="text" name="toemail" size="20"></p>
<p>Subject:<br /><input type="text" name="subject" size="20"></p>
<p>Attachments<br /><input type="file" name="file" size="20"></p>
<p>Content:<br /><textarea rows="2" name="message" cols="20"></textarea></p>
<p> </p>
<p> </p>
<p><input type="submit" value="Send"><input type="reset" value="Reset"></p>
</form>
</body>
</html>
mail.php
<?php
$toemail = $HTTP_POST_VARS['toemail'];
$fromemail = "testing@hotmail.com";
$subject = $HTTP_POST_VARS['subject'];
$attachments = $HTTP_POST_VARS['file'];
$message = $HTTP_POST_VARS['message'];
function send_mail($toemail, $fromemail, $subject, $message, $attachments=flase)
{
$eol="\r\n";
$mime_boundary=md5(time());
$headers .= 'From: MyName<'.$fromemail.'>'.$eol;
$headers .= 'Reply-To: MyName<'.$fromemail.'>'.$eol;
$headers .= 'Return-Path: MyName<'.$fromemail.'>'.$eol;
$headers .= "Message-ID: <".$now." [email=TheSystem@".$_SERVER[]TheSystem@".$_SERVER['SERVER_NAME'].">".$eol[/email];
$headers .= "X-Mailer: PHP v".phpversion().$eol;
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
$msg = "";
if ($attachments !== false)
{
for($i=0; $i < count($attachments); $i++)
{
if (is_file($attachments[$i]["file"]))
{
$file_name = substr($attachments[$i]["file"], (strrpos($attachments[$i]["file"], "/")+1));
$handle=fopen($attachments[$i]["file"], 'rb');
$f_contents=fread($handle, filesize($attachments[$i]["file"]));
$f_contents=chunk_split(base64_encode($f_contents)); //Encode The Data For Transition using base64_encode();
fclose($handle);
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: ".$attachments[$i]["content_type"]."; name=\"".$file_name."\"".$eol;
$msg .= "Content-Transfer-Encoding: base64".$eol;
$msg .= "Content-Disposition: attachment; filename=\"".$file_name."\"".$eol.$eol; // !! This line needs TWO end of lines !! IMPORTANT !!
$msg .= $f_contents.$eol.$eol;
}
}
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= $message.$eol.$eol;
$msg .= "--".$mime_boundary."--".$eol.$eol;
ini_set(sendmail_from,$fromemail); // the INI lines are to force the From Address to be used !
mail($toemail, $subject, $msg, $headers);
ini_restore(sendmail_from);
echo "mail sent successfully";
}
send_mail($toemail, $fromemail, $subject, $message, $attachments);
?>
我用IIS Localhost走我的EMAIL PROGRAM,但是SHOW
PHP Parse error: parse error, unexpected $end in C:\Inetpub\wwwroot\mail.php on line 62
请问我哪里弄错了?
[ 本帖最后由 三分手 于 4-2-2007 03:17 AM 编辑 ] |
|
|
|
|
|
|
|
发表于 4-2-2007 08:59 AM
|
显示全部楼层
If i not wrong you less 1 "}" closing
You like got 4 "{" open but only got 3 "}" close
Sorry cannot use chinese to reply due to in company |
|
|
|
|
|
|
|

楼主 |
发表于 4-2-2007 10:56 AM
|
显示全部楼层
谢谢提醒。
更改了,虽然显示发送成功。
但是发送地址依然没收到。
我想知道PHP。INI怎样SET?
SMTP SET成什么?还有SENDMAIL_FROM SET去哪里? |
|
|
|
|
|
|
|

楼主 |
发表于 4-2-2007 11:59 AM
|
显示全部楼层
回复 #3 三分手 的帖子
终于发送成功了。但是只有SUBJECT和自己的发送地址。但是没有ATTACHMENT和MESSAGE BODY。还在研究当中。。。
这次我直接UPLOAD上WEB HOSTING。
这是最新的CODING。。。各位老大,帮帮忙。。。很BLUR,可能有什么小错误。
<?php
$toemail = $HTTP_POST_VARS['toemail'];
$fromemail = "testing@gmail.com";
$subject = $HTTP_POST_VARS['subject'];
$attachments = $HTTP_POST_VARS['file'];
$message = $HTTP_POST_VARS['message'];
function send_mail($toemail, $fromemail, $subject, $message, $attachments=flase)
{
$eol="\r\n";
$mime_boundary=md5(time());
$headers .= 'From: MyName<'.$fromemail.'>'.$eol;
$headers .= 'Reply-To: MyName<'.$fromemail.'>'.$eol;
$headers .= 'Return-Path: MyName<'.$fromemail.'>'.$eol;
$headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol;
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
$msg = "";
if ($attachments !== false)
{
for($i=0; $i < count($attachments); $i++)
{
if (is_file($attachments[$i]["file"]))
{
$file_name = substr($attachments[$i]["file"], (strrpos($attachments[$i]["file"], "/" +1));
$handle=fopen($attachments[$i]["file"], 'rb');
$f_contents=fread($handle, filesize($attachments[$i]["file"]));
$f_contents=chunk_split(base64_encode($f_contents)); //Encode The Data For Transition using base64_encode();
fclose($handle);
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: ".$attachments[$i]["content_type"]."; name=\"".$file_name."\"".$eol;
$msg .= "Content-Transfer-Encoding: base64".$eol;
$msg .= "Content-Disposition: attachment; filename=\"".$file_name."\"".$eol.$eol; // !! This line needs TWO end of lines !! IMPORTANT !!
$msg .= $f_contents.$eol.$eol;
}
}
# Setup for text OR html
$msg .= "Content-Type: multipart/alternative".$eol;
# Text Version
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= strip_tags(str_replace("<br>", "\n", $message)).$eol.$eol;
# HTML Version
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= $message.$eol.$eol;
$msg .= "--".$mime_boundary."--".$eol.$eol;
ini_set(sendmail_from,$fromemail); // the INI lines are to force the From Address to be used !
mail($toemail, $subject, $msg, $headers);
ini_restore(sendmail_from);
echo "mail sent successfully";
}
}
send_mail($toemail, $fromemail, $subject, $message, $attachments);
?> |
|
|
|
|
|
|
|

楼主 |
发表于 10-2-2007 11:57 PM
|
显示全部楼层
真的没有人懂 ?? |
|
|
|
|
|
|
|
发表于 11-2-2007 12:25 AM
|
显示全部楼层
原帖由 三分手 于 10-2-2007 11:57 PM 发表
真的没有人懂 ??
你知道吗? 懂的人也不见得一定会回答你。 |
|
|
|
|
|
|
|
发表于 11-2-2007 01:30 AM
|
显示全部楼层
把你的 $msg 打印出来看看... 另外, 你应该是少了 if else, 因为你的 $msg 有着 text 和 html 版本. |
|
|
|
|
|
|
|

楼主 |
发表于 3-3-2007 06:35 PM
|
显示全部楼层
回复 #7 goatstudio 的帖子
有谁会EMAIL ATTACHMENT吗?因为我的CODE依然不行。。。有类似经验的,给予提示,好吗? |
|
|
|
|
|
|
| |
本周最热论坛帖子
|