Sending Mail From PHP
Posted: Tue Aug 09, 2011 2:36 pm
I am trying to use PHP to send email on Windows 7. I have installed xampp. I am running this code:
from both the command line and via Apache embedded in an HTML file.
Here is what I get from the command line:
I have configured the php.ini file as follows:
Please let me know if I have left out any necessary information.
Code: Select all
<?php
$result = mail("samfredland@gmail.com", "Test Email", "Hi there, Sam!", "From:sam@localhost");
if ($result) {
echo "Success!";
}
else
echo "Failure.";
?>
Here is what I get from the command line:
BTW, I never get the email.C:\xampp\php>php hello.php
sendmail: Error during delivery: Socket Error # 10061
Connection refused.
Success!
I have configured the php.ini file as follows:
Code: Select all
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = samfredland@gmail.com
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = "\"C:\xampp\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_parameters =
; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = Off
; Log all mail() calls including the full path of the script, line #, to address and headers
;mail.log = "C:\xampp\apache\logs\php_mail.log"