linux下直接mail
<?php
// The message
$message = "Line 1\nLine 2\nLine 3";// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);// Send
mail('[email protected]', 'My Subject', $message);
?>
<?php
// The message
$message = "Line 1\nLine 2\nLine 3";// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);// Send
mail('[email protected]', 'My Subject', $message);
?>
private $mEmails;
function setEmailInfo( $emails ){
if( is_array( $emails ) ){
$this->mEmails['email_to'] = $emails['email_to'];
#对邮件标题进行处理
if( isset( $emails['email_subject'] ) || !empty($emails['email_subject'])) {
eval("\$email_subject = \"".$emails['email_subject']."\";");
$email_subject = str_replace("\r", '', str_replace("\n", '', $emails['email_subject'] ));
$this->mEmails['email_subject'] = $emails['email_subject'];
}
#对邮件内容进行处理
if( isset( $emails['email_message']) || !empty($emails['email_message'])) {
eval("\$email_message = \"".$emails['email_message']."\";");
$emails['email_message'] = str_replace("\r\n.", " \r\n..", str_replace("\n", "\r\n", str_replace("\r", "\n", str_replace("\r\n", "\n", str_replace("\n\r", "\r", $emails['email_message'])))));
$this->mEmails['email_message'] = $emails['email_message'];
}
#对邮件来源进行处理
if( isset($emails['email_from']) || !empty($emails['email_from']))
$this->mEmails['email_from'] = $emails['email_from'];
else
$this->mEmails['email_from'] = '<'.$_SERVER['SERVER_ADMIN'].'>';
}
}
function getEmails( $elements ){
if( isset( $elements ) || !empty( $elements ))
return $this->mEmails[$elements];
else
return $this->mEmails;
}
function __destruct(){
unset( $this );
}
}
class sendMail extends MailCls{
private $mMailCfg;
function __construct( $mailcfg ){
if(is_array( $mailcfg ))
$this->mMailCfg = $mailcfg;
}
#发送邮件函数
function sendMails( ){
if(!$fp = fsockopen($this->mMailCfg['server'], $this->mMailCfg['port'], $errno, $errstr, 30)) {
errorlog('SMTP', "($this->mMailCfg[server]:$this->mMailCfg[port]) CONNECT - Unable to connect to the SMTP server, please check your \"mail_config.php\".", 0);
}
stream_set_blocking($fp, true); $lastmessage = fgets($fp, 512);
if(substr($lastmessage, 0, 3) != '220') {
errorlog('SMTP', "$this->mMailCfg[server]:$this->mMailCfg[port] CONNECT - $lastmessage", 0);
} fputs($fp, ($this->mMailCfg['auth'] ? 'EHLO' : 'HELO')." hoodong\r\n");
$lastmessage = fgets($fp, 512);
if(substr($lastmessage, 0, 3) != 220 && substr($lastmessage, 0, 3) != 250) {
errorlog('SMTP', "($this->mMailCfg[server]:$this->mMailCfg[port]) HELO/EHLO - $lastmessage", 0);
} while(1) {
$lastmessage = fgets($fp, 512);
if(substr($lastmessage, 3, 1) != '-' || empty($lastmessage)) {
break;
}
} if($this->mMailCfg['auth']) {
fputs($fp, "AUTH LOGIN\r\n");
$lastmessage = fgets($fp, 512);
if(substr($lastmessage, 0, 3) != 334) {
errorlog('SMTP', "($this->mMailCfg[server]:$this->mMailCfg[port]) AUTH LOGIN - $lastmessage", 0);
} fputs($fp, base64_encode($this->mMailCfg['auth_username'])."\r\n");
$lastmessage = fgets($fp, 512);
if(substr($lastmessage, 0, 3) != 334) {
errorlog('SMTP', "($this->mMailCfg[server]:$this->mMailCfg[port]) USERNAME - $lastmessage", 0);
} fputs($fp, base64_encode($this->mMailCfg['auth_password'])."\r\n");
$lastmessage = fgets($fp, 512);
if(substr($lastmessage, 0, 3) != 235) {
errorlog('SMTP', "($this->mMailCfg[server]:$this->mMailCfg[port]) PASSWORD - $lastmessage", 0);
} $email_from = $this->mMailCfg['from'];
} fputs($fp, "MAIL FROM: ".preg_replace("/.*\<(.+?)\>.*/", "\\1", $this->getEmails('email_from'))."\r\n");
$lastmessage = fgets($fp, 512);
if(substr($lastmessage, 0, 3) != 250) {
fputs($fp, "MAIL FROM: <".preg_replace("/.*\<(.+?)\>.*/", "\\1", $this->getEmails('email_from')).">\r\n");
$lastmessage = fgets($fp, 512);
if(substr($lastmessage, 0, 3) != 250) {
errorlog('SMTP', "($this->mMailCfg[server]:$this->mMailCfg[port]) MAIL FROM - $lastmessage", 0);
}
} foreach(explode(',', $this->getEmails('email_to')) as $to_user) {
$to_user = trim( $to_user );
if( $to_user ) {
fputs( $fp, "RCPT TO: $to_user\r\n" );
$lastmessage = fgets( $fp, 512 );
if(substr($lastmessage, 0, 3) != 250) {
fputs($fp, "RCPT TO: <$to_user>\r\n");
$lastmessage = fgets($fp, 512);
errorlog('SMTP', "($this->mMailCfg[server]:$this->mMailCfg[port]) RCPT TO - $lastmessage", 0);
}
}
} fputs($fp, "DATA\r\n");
$lastmessage = fgets($fp, 512);
if(substr($lastmessage, 0, 3) != 354) {
errorlog('SMTP', "($this->mMailCfg[server]:$this->mMailCfg[port]) DATA - $lastmessage", 0);
} fputs($fp, "To: ".$this->getEmails('email_to')."\r\nFrom: ".$this->getEmails('email_from')."\r\nSubject: ".str_replace("\n", ' ', $this->getEmails('email_subject'))."\r\n\r\n".$this->getEmails('email_message')."\r\n.\r\n");
fputs($fp, "QUIT\r\n");
}
function getEmailCfg( $elements ){
if(isset( $elements ) || !empty( $elements ))
return $this->mMailCfg[$elements];
else
return $this->mMailCfg;
}
}
* @author [email protected]
* @version 1.0
* @final 2006-09-12
* @package SendMailCls.php
* @param socket邮件发送类
* @var emails和mailcfg应该是array或者hash,其中包含了一些有关邮件的设置信息,具体请看example
* @example:
*/
$emails = array(
'email_to' => '[email protected]', #收件人地址
'email_subject' => 'test', #邮件标题
'email_message' => 'ksadasdasdasdsadasfafdasfdsaff', #邮件正文
'email_from' => 'Hoodong <[email protected]>', #邮件来源
);
$mailcfg['server'] = 'mail.hoodong.com'; #smtp服务器地址
$mailcfg['port'] = '25'; #smtp端口
$mailcfg['auth'] = 1; #显示作者
$mailcfg['from'] = 'Hoodong <[email protected]>'; #发件人地址
$mailcfg['auth_username'] = '[email protected]'; #发件人邮箱
$mailcfg['auth_password'] = '1234567'; #发件人邮箱密码$sm = new sendMail( $mailcfg );
$sm->setEmailInfo( $emails );
$sm->sendMails();
然后在你要发送邮件的页面,include_once('sendMail.class.php');
再然后,按照我上面给你的那个例子,声明两个数组并修改为你自己的信息:$emails = array(
'email_to' => '[email protected]', #收件人地址
'email_subject' => 'test', #邮件标题
'email_message' => 'ksadasdasdasdsadasfafdasfdsaff', #邮件正文
'email_from' => 'Hoodong <[email protected]>', #邮件来源
);$mailcfg['server'] = 'mail.hoodong.com'; #smtp服务器地址
$mailcfg['port'] = '25'; #smtp端口
$mailcfg['auth'] = 1; #显示作者
$mailcfg['from'] = 'Hoodong <[email protected]>'; #发件人地址
$mailcfg['auth_username'] = '[email protected]'; #发件人邮箱
$mailcfg['auth_password'] = '1234567'; #发件人邮箱密码然后:
$sm = new sendMail( $mailcfg );
$sm->setEmailInfo( $emails );
$sm->sendMails();就可以发送邮件了。你试试吧。
sendMail是继承的MailCls类,这两个类放在一个文件里面。然后其他文件调用
<td>所在地区:</td>
<td width="39">国家:</td>
<td width="92">
<select name="country">
<option value="中国大陆" selected="selected">中国大陆</option>
</select>
</td>
<td width="41">地区:</td>
<td width="273">
<select name="area">
<option value="上海">上海</option>
<option value="北京" selected="selected">北京</option>
<option value="天津">天津</option>
<option value="重庆">重庆</option>
<option value="黑龙江">黑龙江</option>
<option value="辽宁">辽宁</option>
<option value="吉林">吉林</option>
<option value="河北">河北</option>
<option value="内蒙古">内蒙古</option>
<option value="陕西">陕西</option>
<option value="山西">山西</option>
<option value="甘肃">甘肃</option>
<option value="宁夏">宁夏</option>
<option value="新疆">新疆</option>
<option value="西藏">西藏</option>
<option value="青海">青海</option>
<option value="四川">四川</option>
<option value="云南">云南</option>
<option value="贵州">贵州</option>
<option value="湖南">湖南</option>
<option value="湖北">湖北</option>
<option value="河南">河南</option>
<option value="山东">山东</option>
<option value="安徽">安徽</option>
<option value="江苏">江苏</option>
<option value="浙江">浙江</option>
<option value="广东">广东</option>
<option value="广西">广西</option>
<option value="江西">江西</option>
<option value="福建">福建</option>
<option value="海南">海南</option>
</select><font color="#FF0000">*</font>
</td>
</tr>$sql="insert into custmer (custmerId,userName,email,password,sex,bandName,country,area,mobilNumber,userLevel,musicKind,ageHood,photoPath,registDate) " .
"values('$custmerId','$userName','$email','$password','$sex','$bandName','$country','$area','$mobilNumber','1','$musicKind','$ageHood','',now())";怎么插不进啊? 我把他们的VALUE改成数字就可以不然他给我报的是Data too long for column 'country' at row 1 什么意思咯.