PHP code
<?PHP//Recipient Email Address$to= ' [email protected] ';//Message Subject$title= ' Test mail send ';//Message Content$msg= ' This is a test e-mail ';//Sender's mailbox (virtual, which itself is not used when sending the mailbox)$from= ' From: [email protected] ';$flag=Mail($to,$title,$msg,$from);//Prints the result, if does not add var_dump will have the null value conversion, namely null turns "Echo Var_dump($flag);?>
Http://www.w3school.com.cn/php/php_ref_mail.asp
In the W3cschool face this piece of some introduction, but no way to directly use, there is a problem.
Blue here only introduce XAMPP integrated installation of the situation, in fact, are the same, and then go to download a sendmail can also, this way XAMPP has been downloaded
Modify the configuration, a total of 2 configuration files.
Under the XAMPP installation directory
php/php.ini
[Mail function];Xampp:comment out the If you want to work with a SMTP Server like MercurySMTP = smtp.163. com smtp_port= 25;For Win32 only.;Http://php.net/sendmail-fromSendmail_from = [email protected]. com;XAMPP IMPORTANT Note (1): If XAMPP is installed in a base directory with spaces (e.g. C:\Program Filesf:\xampp) Fakem Ail and Mailtodisk do not work correctly.;XAMPP IMPORTANT Note (2): In this case please copy the SendMail or Mailtodisk folder in your root folder (e.g. C:\sen DMail) and use the for Sendmail_path. ;Xampp:comment out this if you want to work with Fakemail for forwarding to your mailbox (Sendmail.exe in the Sendmai L folder)Sendmail_path = "F:\xampp\sendmail\sendmail.exe-t";Xampp:comment out this if you want to work with Mailtodisk, It writes all mails in the F:\xampp\mailoutput folder;sendmail_path= "F:\xampp\mailtodisk\mailtodisk.exe";Force the addition of the specified parameters to be passed as extra parameters;To the sendmail binary. These parameters would always replace the value of;the 5th parameter to mail (), even in safe mode.;mail.force_extra_parameters =;ADD X-php-originating-script:that would include UID of the Script followed by the filenameMail.add_x_header=Off;Log All mail () calls including the full path of the script, line #, to address and headers;Mail.log = "F:\xampp\php\logs\php_mail.log"
Mainly change these three configurations, this way blue with 163 SMTP server, Sendmail_path equals to specify a client to send mail, here XAMPP integrated SendMail, also in the installation directory
; plugin for sending mail sendmail_path = "F:\xampp\sendmail\sendmail.exe-t"
Then modify the Sendmail.ini in the SendMail directory
[SendMail];You must the mail.mydomain.com to your SMTP server,;or to IIS ' s "pickup" directory. (generally C:\Inetpub\mailroot\Pickup);emails delivered via IIS ' s pickup directory cause sendmail to;run quicker, but you won ' t get error messages back to the calling;application.Smtp_server=smtp.163. com;SMTP port (normally)Smtp_port=25;SMTPS (SSL) support;auto = Use SSL for port 465, otherwise try-to-use TLS;SSL = alway Use SSL;TLS = Always use TLS;none = Never try to use SSLSmtp_ssl=Auto;The Default domain for this server would be read from the registry;This'll be appended to E- mail addresses when one isn ' t provided;If you want to override the value in the registry, uncomment and modify;default_domain=mydomain.com;log SMTP errors to Error.log (defaults to same directory as Sendmail.exe);uncomment to enable loggingError_logfile=Error.logdebug_logfile=Debug.log;Create debug log as Debug.log (defaults to same directory as Sendmail.exe);uncomment to enable debugging;Debug_logfile=debug.log;If your SMTP server requires authentication, modify the followingAuth_username=13514087953Auth_password=224119;If your SMTP server uses POP3 before SMTP authentication, modify the;following three lines. Do not enable the unless it is required.Pop3_server=Pop3_username=Pop3_password=;Force the sender of the following email address;This would only affect the "MAIL from" command, it won ' t modify;the "from:" header of the message contentForce_sender[Email protected]. com;Force the sender of the following email address;This would only affect the "RCTP to" command, it won ' t modify;The "to:" header of the message contentforce_recipient=;SendMail'll use your hostname and your default_domain in the Ehlo/helo;SMTP Greeting. You can manually set the Ehlo/helo name if requiredhostname=
Major changes (in fact, some duplicate in the Php.inf file can not be set or can)
; SMTP server smtp_server=smtp.163. com; Port smtp_port=25; The sender's mailbox name auth_username=13514087953; password auth_password=224119; Sender e-mail address [Email protected]
Test it with the PHP code at the beginning, and you can run it directly in the IDE.
PHP Mail DEMO (program code to send mail directly)