PHP MAIL DEMO(程序代码直接发送邮件)
2014-08-27 16:26
399 查看
php代码
http://www.w3school.com.cn/php/php_ref_mail.asp
在w3cschool里面对这块有些介绍,但没办法直接用,有问题。
淡蓝这里只介绍xampp集成安装的情况,其实都是一样的,自己再去下载一个sendmail也可以,这边xampp已经下载好了
修改一下配置,一共2个配置文件。
在xampp安装目录下
php/php.ini
主要改这三个配置,这边淡蓝用的是163的smtp服务器,sendmail_path等于指定一个用来发送邮件的客户端,这里xampp集成了sendmail,也在安装目录下
主要修改(其实有些重复的在php.inf文件中就可以不用设置也可以)
用开头的php代码测试一下即可,可以直接在ide中运行
<?php //收件人邮箱地址 $to='xxxxxx@qq.com'; //邮件主题 $title='测试邮件发送'; //邮件内容 $msg='这是一封测试邮件'; //发件人邮箱(虚拟的,本身发送的时候并不是用这个邮箱) $from='From:xxxxxxx@qq.com'; $flag=mail($to,$title,$msg,$from); //打印结果,如果不加var_dump会有空值转换,即null转成‘’ echovar_dump($flag); ?>
在w3cschool里面对这块有些介绍,但没办法直接用,有问题。
淡蓝这里只介绍xampp集成安装的情况,其实都是一样的,自己再去下载一个sendmail也可以,这边xampp已经下载好了
修改一下配置,一共2个配置文件。
在xampp安装目录下
php/php.ini
[mailfunction] ;XAMPP:CommentoutthisifyouwanttoworkwithanSMTPServerlikeMercury SMTP=smtp.163.com smtp_port=25 ;ForWin32only. ;http://php.net/sendmail-fromsendmail_from=13514087953@163.com ;XAMPPIMPORTANTNOTE(1):IfXAMPPisinstalledinabasedirectorywithspaces(e.g.c:\programfilesF:\xampp)fakemailandmailtodiskdonotworkcorrectly. ;XAMPPIMPORTANTNOTE(2):Inthiscasepleasecopythesendmailormailtodiskfolderinyourrootfolder(e.g.C:\sendmail)andusethisforsendmail_path. ;XAMPP:Commentoutthisifyouwanttoworkwithfakemailforforwardingtoyourmailbox(sendmail.exeinthesendmailfolder) sendmail_path="F:\xampp\sendmail\sendmail.exe-t" ;XAMPP:CommentoutthisifyouwanttoworkwithmailToDisk,ItwritesallmailsintheF:\xampp\mailoutputfolder ;sendmail_path="F:\xampp\mailtodisk\mailtodisk.exe" ;Forcetheadditionofthespecifiedparameterstobepassedasextraparameters ;tothesendmailbinary.Theseparameterswillalwaysreplacethevalueof ;the5thparametertomail(),eveninsafemode. ;mail.force_extra_parameters= ;AddX-PHP-Originating-Script:thatwillincludeuidofthescriptfollowedbythefilename mail.add_x_header=Off ;Logallmail()callsincludingthefullpathofthescript,line#,toaddressandheaders ;mail.log="F:\xampp\php\logs\php_mail.log"
主要改这三个配置,这边淡蓝用的是163的smtp服务器,sendmail_path等于指定一个用来发送邮件的客户端,这里xampp集成了sendmail,也在安装目录下
;用来发邮件的插件 sendmail_path="F:\xampp\sendmail\sendmail.exe-t"
然后修改sendmail目录下的sendmail.ini
[sendmail] ;youmustchangemail.mydomain.comtoyoursmtpserver, ;ortoIIS's"pickup"directory.(generallyC:\Inetpub\mailroot\Pickup) ;emailsdeliveredviaIIS'spickupdirectorycausesendmailto ;runquicker,butyouwon'tgeterrormessagesbacktothecalling ;application. smtp_server=smtp.163.com ;smtpport(normally25) smtp_port=25 ;SMTPS(SSL)support ;auto=useSSLforport465,otherwisetrytouseTLS ;ssl=alwayuseSSL ;tls=alwaysuseTLS ;none=nevertrytouseSSL smtp_ssl=auto ;thedefaultdomainforthisserverwillbereadfromtheregistry ;thiswillbeappendedtoemailaddresseswhenoneisn'tprovided ;ifyouwanttooverridethevalueintheregistry,uncommentandmodify ;default_domain=mydomain.com ;logsmtperrorstoerror.log(defaultstosamedirectoryassendmail.exe) ;uncommenttoenablelogging error_logfile=error.log debug_logfile=debug.log ;createdebuglogasdebug.log(defaultstosamedirectoryassendmail.exe) ;uncommenttoenabledebugging ;debug_logfile=debug.log ;ifyoursmtpserverrequiresauthentication,modifythefollowingtwolines auth_username=13514087953 auth_password=224119 ;ifyoursmtpserverusespop3beforesmtpauthentication,modifythe ;followingthreelines.donotenableunlessitisrequired. pop3_server= pop3_username= pop3_password= ;forcethesendertoalwaysbethefollowingemailaddress ;thiswillonlyaffectthe"MAILFROM"command,itwon'tmodify ;the"From:"headerofthemessagecontent force_sender=13514087953@163.com ;forcethesendertoalwaysbethefollowingemailaddress ;thiswillonlyaffectthe"RCTPTO"command,itwon'tmodify ;the"To:"headerofthemessagecontent force_recipient= ;sendmailwilluseyourhostnameandyourdefault_domainintheehlo/helo ;smtpgreeting.youcanmanuallysettheehlo/helonameifrequired hostname=
主要修改(其实有些重复的在php.inf文件中就可以不用设置也可以)
;smtp服务器 smtp_server=smtp.163.com ;端口 smtp_port=25 ;发件人邮箱名 auth_username=13514087953 ;密码 auth_password=224119 ;发件人邮箱地址 force_sender=13514087953@163.com
用开头的php代码测试一下即可,可以直接在ide中运行
相关文章推荐
- 程序异常退出时发送邮件报告的代码
- 程序异常退出时发送邮件报告的代码
- Android 后台发送邮件 (收集应用异常信息+Demo代码)
- 程序异常退出时发送邮件报告的代码
- .Net 邮件发送的类,在程序中直接调用就可以了
- Android 后台发送邮件示例 (收集应用异常信息+Demo代码)
- Android 后台发送邮件 (收集应用异常信息+Demo代码)
- Android 后台发送邮件 (收集应用异常信息+Demo代码)
- 程序异常退出时发送邮件报告的代码
- 使用.net程序发送邮件代码
- 程序异常退出时发送邮件报告的代码
- java mail发送邮件demo 代码
- 应用中调用 iPhone 自带 Mail 程序发送邮件的代码
- 程序异常退出时发送邮件报告的代码
- 程序异常退出时发送邮件报告的代码
- 程序异常退出时发送邮件报告的代码
- 程序异常退出时发送邮件报告的代码
- Android 后台发送邮件 (收集应用异常信息+Demo代码)
- 程序异常退出时发送邮件报告的代码
- 程序异常退出时发送邮件报告的代码