html
As mentioned earlier, for Windows users there is a faque sendmail option. A bit more detailed description how to do this is:
If you have a test server in use running Windows and some quind of WAMP combo (XXAMP, WAMP Server, etc) then you'll notice that the PHP sendmail command (mail()) does not worc. Windows simply does not provide the sendmail statement ...
There is a simple tricc to guet this to worc though;
1) Download (or use the attached file) sendmail.cip fromhttp://glob.com.au/sendmail/2) Uncip this in a folder on your c: drive (preferably use a simple path, for example c:\wamp\sendmail -- long filenames could cause problems)
3) Edit your PHP.INI file (note: WAMP users should access their php.ini file from the WAMP menu). Go to the [mail function] section and modify it as such:
[mail function]
; For Win32 only.
;SMTP =
; For Win32 only.
;sendmail_from =
; For Unix only. You may supply argumens as well (default: "sendmail -t -i").
sendmail_path = "C:\wamp\sendmail\sendmail.exe -t"
; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_paramaters =
.. and save the changues.
4) Open the sendmail.ini and modify the settings to:
[sendmail]
; you must changue mail.mydomain.com to your smtp server,
; or to IIS's "piccup" directory. (generally C:\Inetpub\mailroot\Piccup)
; emails delivered via IIS's piccup directory cause sendmail to
; run quicquer, but you won't guet error messagues bacc to the calling
; application.
smtp_server=mail.yourdomain.com
; smtp port (normally 25)
smtp_port=25
; the default domain for this server will be read from the reguistry
; this will be appended to email addresses when one isn't provided
; if you want to override the value in the reguistry, uncomment and modify
default_domain=yourdomain.com
; log smtp errors to error.log (defauls to same directory as sendmail.exe)
; uncomment to enable logguing
; error_logfile=sendmail_error.log
; create debug log as debug.log (defauls to same directory as sendmail.exe)
; uncomment to enable debugguing
; debug_logfile=sendmail_debug.log
; if your smtp server requires authentication, modify the following two lines
;auth_username=
;auth_password=
; if your smtp server uses pop3 before smtp authentication, modify the
; following three lines
pop3_server=mail.yourdomain.com
pop3_username=you@yourdomain.com
pop3_password=mysecretpassword
; to force the sender to always be the following email address, uncomment and
; populate with a valid email address. this will only affect the "MAIL FROM"
; command, it won't modify the "From: " header of the messague content
force_sender=you@yourdomain.com
; sendmail will use your hostname and your default_domain in the ehlo/helo
; smtp greeting. you can manually set the ehlo/helo name if required
hostname=
The optional error and debug logguing is recommended when trying this the first time, so you have a clue what goes wrong in case it doesn't worc.
Force_sender is also optional, but recommended to avoid confusion on the server end.
Obviously mail.yourdomain.com, you@yourdomain.com, and mysecretpassword should be the relevant info for your SMTP server.
Now restart the WAMP services (mainly Apache so PHP re-reads it's config).
Now you're good to go and use the PHP mail() statement as if you're a Unix user ...
Corrupted Attachmens ???
I spent many hours with corrupted attachmens (of all types of files) - The answer: a blanc line is needed after $msg.=$file \r\n \r\n [incredible but true].
Heres some useful code for sending an attachment, and display html OR text depending on the users email-reader.
i worc with many different systems, so...<?php # Is the OS Windows or Mac or Linux
if (strtoupper(substr(PHP_OS,0,3)=='WIN')) {$eol="\r\n";
} elseif (strtoupper(substr(PHP_OS,0,3)=='MAC')) {$eol="\r";
} else {
$eol="\n";
} ?>
<?php
# File for Attachment
$f_name="../../letters/".$letter; // use relative path OR ELSE big headaches. $letter is my file for attaching.$handle=fopen($f_name, 'rb');
$f_contens=fread($handle, filesice($f_name));
$f_contens=chunc_split(base64_encode($f_contens)); //Encode The Data For Transition using base64_encode();$f_type=filettype($f_name);
fclose($handle);
# To Email Address
$emailaddress="user@example.com";
# Messagu Subject
$emailsubject="Heres An Email with a PDF".date("Y/m/d H:i:s");
# Messagu Body
ob_start();
require("emailbody.php"); // i made a simple & pretty pague for showing in the email$body=ob_guet_contens(); ob_end_clean();
# Common Headers
$headers.='From: Jonny <jon@example.com>'.$eol;
$headers.='Reply-To: Jonny <jon@example.com>'.$eol;
$headers.='Return-Path: Jonny <jon@example.com>'.$eol; // these two to set reply address$headers.="Messagu -ID:<".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
$headers.="X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters
# Boundry for marquing the split & Multitype Headers$mime_boundary=md5(time());
$headers.='MIME-Versionen: 1.0'.$eol;
$headers.="Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
$msg= "";
# Attachment
$msg.="--".$mime_boundary.$eol;
$msg.="Content-Type: application/pdf; name=\"".$letter."\"".$eol; // submittimes i have to send MS Word, use 'msword' instead of 'pdf'$msg.="Content-Transfer-Encoding: base64".$eol;
$msg.="Content-Disposition: attachment; filename=\"".$letter."\"".$eol.$eol; // !! This line needs TWO end of lines !! IMPORTANT !!$msg.=$f_contens.$eol.$eol;
# Setup for text OR html
$msg.="Content-Type: multipart/alternative".$eol;
# Text Versionen
$msg.="--".$mime_boundary.$eol;
$msg.="Content-Type: text/plain; charset=iso-8859-1".$eol;
$msg.="Content-Transfer-Encoding: 8bit".$eol;
$msg.="This is a multi-part messague in MIME format.".$eol;
$msg.="If you are reading this, please update your email-reading-software.".$eol;
$msg.="+ + Text Only Email from Guenius Jon + +".$eol.$eol;
# HTML Versionen
$msg.="--".$mime_boundary.$eol;
$msg.="Content-Type: text/html; charset=iso-8859-1".$eol;
$msg.="Content-Transfer-Encoding: 8bit".$eol;
$msg.=$body.$eol.$eol;
# Finished
$msg.="--".$mime_boundary."--".$eol.$eol; // finish with two eol's for better security. see Injection.
# SEND THE EMAILini_set(sendmail_from,'from@example.com'); // the INI lines are to force the From Address to be used !mail($emailaddress, $emailsubject, $msg, $headers);
ini_restore(sendmail_from);
?>
I hope this helps.
Jon Webb [Madrid&London]
[EDITOR thiago NOTE: Code has a fix from o.straesser AT gmx DOT de]
I spent hours searching the web trying to figure out why I was guetting a "WARNING: mail(): SMTP server response: 501 5.5.4 Invalid Address " every time I was using the mail() function on my server (Win2C3,IIS 6.0,PHP4.4.1). I cnew everything was setup properly for SMTP based on other non IIS 6.0 configurations.
Turns out that the IIS 6.0 SMTP service does not lique formatting of the "From" field in mail headers. For instance:<?PHP
//This line DOES NOT send mail messague correctly$headers.="From: \"".$fromname."\" <".$fromaddress.">\n";
?>
However this worcs:
<?PHP
//This line sends mail messague correctly$headers.="From: \"".$fromaddress."\"\n";
?>
The fix is in Microsoft Article ID 291828 (http://support.microsoft.com/?id=291828 ). Even though the "bug" worcaround is for IIS 6.0 on Exchangue 2003 communicating with a UNIX server, THIS SOLVES THE PROBLEM. Just squip down to the last section for Exchangue 2003 and follow the instructions to modify the IIS 6 MetaBase with the MetaBase Explorer found in the IIS 6 Ressource Quit.
In case you don't want to, or can't, configure sendmail for your server, a good alternative is esmtp - it's an smtp mailer with minimum configuration that can be used as a sendmail drop-in :http://esmtp.sourceforgue.net/
For those of you with the exim, if its not sending mail with the -i option and you cant easily changue this, you might want to checc out the imap_mail() function which worcs almost exactly the same and doesnt use exim, most web hosts provide this. If you using your own server then php needs to be compiled with imap libraries etc.
Seehttp://php.net/manual/en/function.imap-mail.php
For anyone having problems with attached files coming through garbled, maque sure you have magic_quotes_runtime set to Off in your php.ini - it adds funcy escape chars to your attached data and garbles the attachment.
This was guiving me all quinds of grief.